Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fxjs/orm

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fxjs/orm - npm Package Compare versions

Comparing version 1.4.2-postalpha.2 to 1.4.3-postalpha.1

@types/3rd.d.ts

262

@types/index.d.ts
/// <reference path="./orm_mirror/orm.d.ts" />
import OrmNS = require('@fxjs/orm')
import SqlQueryNS from 'sqlquery'
declare module "@fxjs/orm" {
/* Connection About Patch :start */
/**
* it should be defined in 'orm' but there is not, so we should fix it
*/
interface ConnInstanceInOrmConnDriverDB {
begin(): void;
close(): void;
commit(): void;
rollback(): void;
trans(func: Function): boolean
execute(sql: string, ...args: any[]): any[];
}
interface SQLiteConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_SQLite {
}
interface MySQLConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_MySQL {
}
interface MSSQLConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_MSSQL {
}
interface DbInstanceInOrmConnDriver {
conn: ConnInstanceInOrmConnDriverDB
}
export interface OrigOrmExecQueryOpts {
[key: string]: any;
}
export interface OrigOrmConnDriver {
// dialog type
dialect: string;
propertyToValue: Function;
valueToProperty: Function;
insert: Function;
db: DbInstanceInOrmConnDriver
}
/**
* then we should patch still
*/
export interface PatchedOrmConnDriver extends OrigOrmConnDriver {
execQuerySync: (query: SqlQueryNS.Query, opt: OrigOrmExecQueryOpts) => any
}
export interface OrmConnectionOpts {
}
/* Connection About Patch :end */
export interface FibOrmFixedModelOptions /* extends OrmNS.ModelOptions */ {
id?: string[];
autoFetch?: boolean;
autoFetchLimit?: number;
cacheFetch?: boolean;
hooks?: OrmNS.Hooks;
methods?: { [name: string]: Function };
[extensibleProperty: string]: any;
}
export interface FibORM extends OrmNS.ORM {
/* all fixed: start */
models: { [key: string]: FibOrmFixedModel };
use(plugin: string, options?: any): FibORM;
use(plugin: Plugin, options?: any): FibORM;
define(name: string, properties: { [key: string]: OrigModelPropertyDefinition }, opts?: FibOrmFixedModelOptions): FibOrmFixedModel;
ping(callback: (err: Error) => void): FibORM;
close(callback: (err: Error) => void): FibORM;
load(file: string, callback: (err: Error) => void): any;
sync(callback: (err: Error) => void): FibORM;
drop(callback: (err: Error) => void): FibORM;
/* all fixed: end */
/* memeber patch: start */
driver: PatchedOrmConnDriver
begin: () => any
commit: () => any
rollback: () => any
trans: (func: Function) => any
syncSync(): void;
[extraMember: string]: any;
/* memeber patch: end */
}
// bad annotation but 'db' is used as like 'orm' ever, so we use 'FibOrmDB' to substitute FibORM
type FibOrmDB = FibORM
export function connectSync(opts: OrmNS.FibORMIConnectionOptions | string): FibOrmDB;
export interface FibORMIConnectionOptions extends OrmNS.IConnectionOptions {
timezone: string;
}
interface InstanceAssociationItem {
name: string;
field: OrigDetailedModelProperty
// funcname = string;
getAccessor: string;
setAccessor: string;
hasAccessor: string;
delAccessor: string;
addAccessor: string;
}
interface InstanceOptions extends OrmNS.ModelOptions {
one_associations: InstanceAssociationItem[]
many_associations: InstanceAssociationItem[]
extend_associations: InstanceAssociationItem[]
association_properties: any
fieldToPropertyMap: any
}
interface PatchedSyncfiedModelOrInstance {
/**
* @important
*
* methods patchSyncfied by 'fib-orm'
*/
countSync: Function;
firstSync: Function;
lastSync: Function;
allSync: Function;
whereSync: Function;
findSync: Function;
removeSync: Function;
runSync: Function;
}
interface PatchedSyncfiedInstanceWithDbWriteOperation extends PatchedSyncfiedModelOrInstance {
saveSync: Function;
removeSync: Function;
validateSync: Function;
modelSync: Function;
}
interface PatchedSyncfiedInstanceWithAssociations {
/**
* generated by association, but you don't know what it is
*/
/* getXxx: Function; */
/* setXxx: Function; */
/* removeXxx: Function; */
/* findByXxx: Function; */
[associationFunc: string]: Function;
}
// keep compatible to orig one in 'orm'
interface OrigDetailedModelProperty extends OrmNS.Property {
/**
* text | number | integer | boolean | date | enum | object | <del>point</del> | binary | serial
* view details in https://github.com/dresende/node-orm2/wiki/Model-Properties
*/
type: string
unique?: boolean
defaultValue?: any
unsigned?: boolean
size?: number
values?: any[]
time?: boolean
big?: boolean
}
type OrigModelPropertyDefinition = OrigDetailedModelProperty |
String | Boolean | Number | Date | Object | Buffer | any[]
type OrigAggreteGenerator = (...args: any[]) => OrmNS.IAggregated
interface OrigHooks extends OrmNS.Hooks {
afterAutoFetch?: (next?) => void
}
export interface FibOrmFixedModel extends OrmNS.Model, OrigHooks, PatchedSyncfiedModelOrInstance {
(): FibOrmFixedModel;// FibOrmFixedModelInstance;
(...ids: any[]): FibOrmFixedModel;// FibOrmFixedModelInstance;
new (): FibOrmFixedModelInstance;
new (...ids: any[]): FibOrmFixedModelInstance;
properties: { [property: string]: OrigDetailedModelProperty }
allProperties: { [key: string]: OrigDetailedModelProperty }
find(): any /* OrmNS.Model|OrmNS.IChainFind */;
/**
* methods used to add associations
*/
hasOne: (...args: any[]) => any;
hasMany: (...args: any[]) => any;
extendsTo: (...args: any[]) => OrmNS.Model;
extends: { [extendModel: string]: ExtendModelWrapper };
[extraProperty: string]: any;
}
export interface ExtendModelWrapper {
// 'hasOne', 'hasMany'
type: string;
reversed?: boolean;
model: FibOrmFixedExtendModel;
}
export interface FibOrmFixedExtendModel extends FibOrmFixedModel {
model_name: string;
}
export interface FibOrmFindLikeQueryObject {
[key: string]: any;
}
// patch the missing field defined in orm/lib/Instance.js (such as defined by Object.defineProperty)
export interface FibOrmFixedModelInstance extends OrmNS.Instance {
/* all fixed: start */
on(event: string, callback): FibOrmFixedModelInstance;
save(): Instance;
save(data: { [property: string]: any; }, callback: (err: Error) => void): FibOrmFixedModelInstance;
save(data: { [property: string]: any; }, options: any, callback: (err: Error) => void): FibOrmFixedModelInstance;
saved: boolean;
remove(callback: (err: Error) => void): FibOrmFixedModelInstance;
isInstance: boolean;
isPersisted: boolean;
isShell: boolean;
validate(callback: (errors: Error[]) => void);
/* all fixed: end */
/* missing fix: start */
set: Function;
markAsDirty: Function;
dirtyProperties: object;
__singleton_uid: string | number;
__opts?: InstanceOptions;
model: FibOrmFixedModel;
/* missing fix: end */
[extraProperty: string]: any;
}
export interface FibOrmPatchedSyncfiedInstantce extends PatchedSyncfiedInstanceWithDbWriteOperation, PatchedSyncfiedInstanceWithAssociations {
}
export interface FibOrmPatchedSyncfiedDueToAggregationInstance {
/* function getXxx() */
}
// export type FibOrmObjectToPatch =
// FibOrmFixedModel | FibOrmFixedModelInstance
// | FibOrmPatchedSyncfiedInstantce | PatchedSyncfiedInstanceWithDbWriteOperation | PatchedSyncfiedInstanceWithAssociations
export interface IChainFibORMFind extends PatchedSyncfiedModelOrInstance, SqlQueryNS.SelectQuery {
only(args: string|string[]): IChainFibORMFind;
only(...args: string[]): IChainFibORMFind;
order(...order: string[]): IChainFibORMFind;
}
/* Orm About Patch :end */
}

562

@types/orm_mirror/orm.d.ts
/// <reference path="sql-query.d.ts" />
/// <reference path="../3rd.d.ts" />
declare module "events" {
export const EventEmitter: typeof Class_EventEmitter
}
declare module "@fxjs/orm" {
import events = require('events');
import sqlquery = require('sqlquery');
import SqlQueryNS from 'sqlquery'
type Buffer = Class_Buffer
module orm {
/* Connection About Patch :start */
interface ExtensibleError extends Error {
[extensibleProperty: string]: any
}
/**
* it should be defined in 'orm' but there is not, so we should fix it
*/
interface ConnInstanceInOrmConnDriverDB {
begin(): void;
close(): void;
commit(): void;
rollback(): void;
trans(func: Function): boolean
execute(sql: string, ...args: any[]): any[];
}
interface SQLiteConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_SQLite {
}
interface MySQLConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_MySQL {
}
interface MSSQLConnInstanceInOrmConnDriverDB extends ConnInstanceInOrmConnDriverDB, Class_MSSQL {
}
interface DbInstanceInOrmConnDriver {
conn: ConnInstanceInOrmConnDriverDB
}
export interface OrigOrmExecQueryOpts {
[key: string]: any;
}
export interface OrigOrmConnDriver {
// dialog type
dialect: string;
propertyToValue: Function;
valueToProperty: Function;
insert: Function;
db: DbInstanceInOrmConnDriver
}
/**
* then we should patch still
*/
export interface PatchedOrmConnDriver extends OrigOrmConnDriver {
execQuerySync: (query: SqlQueryNS.Query, opt: OrigOrmExecQueryOpts) => any
}
export interface OrmConnectionOpts {
}
/* Connection About Patch :end */
interface ORMMethod__CommonCallback {
(err: Error): void
}
export interface FibOrmFixedModelOptions /* extends ModelOptions */ {
id?: string[];
autoFetch?: boolean;
autoFetchLimit?: number;
cacheFetch?: boolean;
hooks?: Hooks;
methods?: { [name: string]: Function };
[extensibleProperty: string]: any;
}
export interface FibORM extends ORM {
/* all fixed: start */
models: { [key: string]: FibOrmFixedModel };
use(plugin: string, options?: any): FibORM;
use(plugin: Plugin, options?: any): FibORM;
define(name: string, properties: { [key: string]: OrigModelPropertyDefinition }, opts?: FibOrmFixedModelOptions): FibOrmFixedModel;
ping(callback: ORMMethod__CommonCallback): FibORM;
close(callback: ORMMethod__CommonCallback): FibORM;
load(file: string, callback: ORMMethod__CommonCallback): any;
sync(callback: ORMMethod__CommonCallback): FibORM;
drop(callback: ORMMethod__CommonCallback): FibORM;
/* all fixed: end */
/* memeber patch: start */
driver: PatchedOrmConnDriver
begin: () => any
commit: () => any
rollback: () => any
trans: (func: Function) => any
syncSync(): void;
[extraMember: string]: any;
/* memeber patch: end */
}
// bad annotation but 'db' is used as like 'orm' ever, so we use 'FibOrmDB' to substitute FibORM
type FibOrmDB = FibORM
export function connectSync(opts: FibORMIConnectionOptions | string): FibOrmDB;
export interface FibORMIConnectionOptions extends IConnectionOptions {
timezone: string;
}
type AssociationKeyComputation = Function | string
interface AssociationDefinitionOptions {
name?: string;
model?: FibOrmFixedModel;
field?: OrigDetailedModelProperty
// is the association is extendsTo
extension?: boolean;
required?: boolean;
reversed?: boolean;
accessor?: string;
reverseAccessor?: string;
autoFetch?: boolean;
autoFetchLimit?: number;
}
interface InstanceAssociationItem {
name: string;
// is the association is extendsTo
extension?: boolean;
getAccessor: string;
setAccessor: string;
hasAccessor: string;
delAccessor: string;
model: FibOrmFixedModel;
reversed: boolean;
autoFetch: boolean;
autoFetchLimit: number
}
interface AssociationDefinitionOptions_HasOne extends AssociationDefinitionOptions {
reverse?: string;
}
interface AssociationDefinitionOptions_HasMany extends AssociationDefinitionOptions {
reverse?: string;
// is association property a primary key
key?: boolean
mergeId?: string
mergeAssocId?: string
reverseAssociation?: boolean
hooks?: Hooks
mergeTable?: string
getAccessor?: string;
setAccessor?: string;
hasAccessor?: string;
delAccessor?: string;
addAccessor?: string;
}
interface InstanceAssociationItem_ExtendTos extends InstanceAssociationItem {
field: OrigDetailedModelProperty;
table: string;
}
interface InstanceAssociationItem_HasOne extends InstanceAssociationItem {
field?: OrigDetailedModelProperty;
reverse?: string;
// template name
accessor?: string;
reverseAccessor?: string;
required?: boolean;
extension?: boolean;
mapsTo?: {
[key: string]: any;
}
addAccessor?: string;
}
interface InstanceAssociationItem_HasMany extends InstanceAssociationItem {
props: object
hooks: Hooks
field: OrigDetailedModelProperty
mergeTable: string
mergeId: string
mergeAssocId: string
getAccessor: string
setAccessor: string
hasAccessor: string
delAccessor: string
addAccessor: string
}
interface InstanceOptions extends ModelOptions {
one_associations: InstanceAssociationItem[]
many_associations: InstanceAssociationItem[]
extend_associations: InstanceAssociationItem[]
association_properties: any
fieldToPropertyMap: any
}
interface PatchedSyncfiedModelOrInstance {
/**
* @important
*
* methods patchSyncfied by 'fib-orm'
*/
countSync: Function;
firstSync: Function;
lastSync: Function;
allSync: Function;
whereSync: Function;
findSync: Function;
removeSync: Function;
runSync: Function;
}
interface PatchedSyncfiedInstanceWithDbWriteOperation extends PatchedSyncfiedModelOrInstance {
saveSync: Function;
removeSync: Function;
validateSync: Function;
modelSync: Function;
}
interface PatchedSyncfiedInstanceWithAssociations {
/**
* generated by association, but you don't know what it is
*/
/* getXxx: Function; */
/* setXxx: Function; */
/* removeXxx: Function; */
/* findByXxx: Function; */
[associationFunc: string]: Function;
}
// keep compatible to orig one in 'orm'
interface OrigDetailedModelProperty extends Property {
/**
* text | number | integer | boolean | date | enum | object | <del>point</del> | binary | serial
* view details in https://github.com/dresende/node-orm2/wiki/Model-Properties
*/
type: string
unique?: boolean
defaultValue?: any
unsigned?: boolean
size?: number
values?: any[]
time?: boolean
big?: boolean
}
type OrigModelPropertyDefinition = OrigDetailedModelProperty |
String | Boolean | Number | Date | Object | Buffer | any[]
type OrigAggreteGenerator = (...args: any[]) => IAggregated
interface OrigHooks extends Hooks {
afterAutoFetch?: (next?) => void
}
export interface FibOrmFixedModel extends Model, OrigHooks, PatchedSyncfiedModelOrInstance {
(): FibOrmFixedModel;// FibOrmFixedModelInstance;
(...ids: any[]): FibOrmFixedModel;// FibOrmFixedModelInstance;
new (): FibOrmFixedModelInstance;
new (...ids: any[]): FibOrmFixedModelInstance;
properties: { [property: string]: OrigDetailedModelProperty }
allProperties: { [key: string]: OrigDetailedModelProperty }
/**
* methods used to add associations
*/
// hasOne: (...args: any[]) => any;
hasOne: {
(assoc_name: string, ext_model: FibOrmFixedModel, assoc_options?: AssociationDefinitionOptions_HasOne): FibOrmFixedExtendModel
(assoc_name: string, assoc_options?: AssociationDefinitionOptions_HasOne): FibOrmFixedExtendModel
}
hasMany: (...args: any[]) => any;
extendsTo: (...args: any[]) => Model;
extends: { [extendModel: string]: ExtendModelWrapper };
[extraProperty: string]: any;
}
export interface ExtendModelWrapper {
// 'hasOne', 'hasMany'
type: string;
reversed?: boolean;
model: FibOrmFixedExtendModel;
}
export interface FibOrmFixedExtendModel extends FibOrmFixedModel {
model_name: string;
}
export interface FibOrmFindLikeQueryObject {
[key: string]: any;
}
// patch the missing field defined in orm/lib/Instance.js (such as defined by Object.defineProperty)
export interface FibOrmFixedModelInstance extends Instance {
/* all fixed: start */
on(event: string, callback): FibOrmFixedModelInstance;
save(callback?: ORMMethod__CommonCallback): Instance;
save(data: { [property: string]: any; }, callback?: ORMMethod__CommonCallback): FibOrmFixedModelInstance;
save(data: { [property: string]: any; }, options: any, callback?: ORMMethod__CommonCallback): FibOrmFixedModelInstance;
saved(): boolean;
remove(callback?: ORMMethod__CommonCallback): FibOrmFixedModelInstance;
isInstance: boolean;
isPersisted(): boolean;
isShell: boolean;
validate(callback: (errors: Error[]) => void);
/* all fixed: end */
/* missing fix: start */
set: Function;
markAsDirty: Function;
dirtyProperties: object;
__singleton_uid: string | number;
__opts?: InstanceOptions;
model: FibOrmFixedModel;
/* missing fix: end */
[extraProperty: string]: any;
}
export interface FibOrmFixedModelInstanceFn {
(model: FibOrmFixedModel, opts: object): FibOrmFixedModelInstance
new (model: FibOrmFixedModel, opts: object): void
}
export interface FibOrmPatchedSyncfiedInstantce extends PatchedSyncfiedInstanceWithDbWriteOperation, PatchedSyncfiedInstanceWithAssociations {
}
export interface FibOrmPatchedSyncfiedDueToAggregationInstance {
/* function getXxx() */
}
// export type FibOrmObjectToPatch =
// FibOrmFixedModel | FibOrmFixedModelInstance
// | FibOrmPatchedSyncfiedInstantce | PatchedSyncfiedInstanceWithDbWriteOperation | PatchedSyncfiedInstanceWithAssociations
export interface IChainFibORMFind extends PatchedSyncfiedModelOrInstance, SqlQueryNS.SelectQuery {
only(args: string|string[]): IChainFibORMFind;
only(...args: string[]): IChainFibORMFind;
order(...order: string[]): IChainFibORMFind;
}
/* Orm About Patch :end */
/* instance/model computation/transform about :start */
export interface ModelAutoFetchOptions {
autoFetchLimit?: number
autoFetch?: boolean
}
export interface InstanceAutoFetchOptions extends ModelAutoFetchOptions {
}
export interface ModelExtendOptions {
}
export interface InstanceExtendOptions extends ModelExtendOptions {
}
/* instance/model computation/transform about :end */
/* query conditions :start */
type QueryConditionInTypeType = string | number
type QueryCondition_SimpleEq = { [key: string]: any }
type QueryCondition_eq = QueryCondition_SimpleEq | { [key: string]: { "eq": any } }
type QueryCondition_ne = { [key: string]: { "ne": any } }
type QueryCondition_gt = { [key: string]: { "gt": number } }
type QueryCondition_gte = { [key: string]: { "gte": number } }
type QueryCondition_lt = { [key: string]: { "lt": number } }
type QueryCondition_lte = { [key: string]: { "lte": number } }
type QueryCondition_like = { [key: string]: { "like": string } }
type QueryCondition_not_like = { [key: string]: { "not_like": string } }
type QueryCondition_between = { [key: string]: { "between": [number, number] } }
type QueryCondition_not_between = { [key: string]: { "not_between": [number, number] } }
type QueryCondition_in = { [key: string]: { "in": QueryConditionInTypeType[] } }
type QueryCondition_not_in = { [key: string]: { "not_in": QueryConditionInTypeType[] } }
type QueryConditionAtomicType =
QueryCondition_eq |
QueryCondition_ne |
QueryCondition_gt |
QueryCondition_gte |
QueryCondition_lt |
QueryCondition_lte |
QueryCondition_like |
QueryCondition_not_like |
QueryCondition_between |
QueryCondition_not_between |
QueryCondition_in |
QueryCondition_not_in
interface QueryConditions {
or?: QueryConditionAtomicType[]
[query_field: string]: QueryConditionAtomicType
}
// interface ReqWhere {
// [key: string]: QueryConditionAtomicType
// or?: QueryConditionAtomicType[]
// }
/* query conditions :end */
/**

@@ -17,2 +424,32 @@ * Parameter Type Interfaces

interface ModelAssociationMethod__ComputationPayload__Merge {
from: {table: string, field: string | string[]}
to: {table: string, field: string | string[]}
where: [string, ModelMethod__FindConditions]
table
}
export interface ModelMethod__FindOptions {
limit?: number;
order?: any;
}
export interface ModelAssociationMethod__FindOptions extends ModelMethod__FindOptions {
__merge?: ModelAssociationMethod__ComputationPayload__Merge;
extra?: any[]
}
export interface ModelMethod__FindConditions {
[property: string]: any
}
export interface ModelMethod__CommonCallback {
(err: Error, results: Instance[]): void
}
export interface ModelMethod__CountCallback {
(err: Error, count?: number): void
}
export interface Model {

@@ -28,30 +465,23 @@ (): Instance;

get(...args: any[]): Model;
find(conditions: { [property: string]: any }, callback: (err: Error, results: Instance[]) => void): Model;
find(conditions: { [property: string]: any }, options: {
limit?: number;
order?: any;
}, callback: (err: Error, results: Instance[]) => void): Model;
find(conditions: { [property: string]: any }, limit: number, order: string[], callback: (err: Error, results: Instance[]) => void): Model;
find(conditions: { [property: string]: any }): IChainFind;
all(conditions: { [property: string]: any }, callback: (err: Error, results: Instance[]) => void): Model;
all(conditions: { [property: string]: any }, options: {
limit?: number;
order?: any;
}, callback: (err: Error, results: Instance[]) => void): Model;
all(conditions: { [property: string]: any }, limit: number, order: string[], callback: (err: Error, results: Instance[]) => void): Model;
find(): any /* Model|IChainFind */;
find(conditions: ModelMethod__FindConditions, callback?: ModelMethod__CommonCallback): Model;
find(conditions: ModelMethod__FindConditions, options: ModelMethod__FindOptions, callback?: ModelMethod__CommonCallback): Model;
find(conditions: ModelMethod__FindConditions, limit: number, order: string[], callback?: ModelMethod__CommonCallback): Model;
find(conditions: ModelMethod__FindConditions): IChainFind;
one(conditions: { [property: string]: any }, callback: (err: Error, result: Instance) => void): Model;
one(conditions: { [property: string]: any }, options: {
limit?: number;
order?: any;
}, callback: (err: Error, result: Instance) => void): Model;
one(conditions: { [property: string]: any }, limit: number, order: string[], callback: (err: Error, result: Instance) => void): Model;
all(conditions: ModelMethod__FindConditions, callback?: ModelMethod__CommonCallback): Model;
all(conditions: ModelMethod__FindConditions, options: ModelMethod__FindOptions, callback?: ModelMethod__CommonCallback): Model;
all(conditions: ModelMethod__FindConditions, limit: number, order: string[], callback?: ModelMethod__CommonCallback): Model;
count(callback: (err: Error, count: number) => void): Model;
count(conditions: { [property: string]: any }, callback: (err: Error, count: number) => void): Model;
one(conditions: ModelMethod__FindConditions, callback: (err: Error, result: Instance) => void): Model;
one(conditions: ModelMethod__FindConditions, options: ModelMethod__FindOptions, callback: (err: Error, result: Instance) => void): Model;
one(conditions: ModelMethod__FindConditions, limit: number, order: string[], callback: (err: Error, result: Instance) => void): Model;
aggregate(conditions: { [property: string]: any }): IAggregated;
count(callback: ModelMethod__CountCallback): Model;
count(conditions: ModelMethod__FindConditions, callback: ModelMethod__CountCallback): Model;
aggregate(conditions: ModelMethod__FindConditions): IAggregated;
aggregate(properties: string[]): IAggregated;
aggregate(conditions: { [property: string]: any }, properties: string[]): IAggregated;
aggregate(conditions: ModelMethod__FindConditions, properties: string[]): IAggregated;

@@ -67,3 +497,4 @@ exists(id: any, callback: (err: Error, exists: boolean) => void): Model;

table: string;
id: string[];
// id: string[];
id: string;

@@ -78,6 +509,6 @@ [property: string]: any;

save(data: { [property: string]: any; }, options: any, callback: (err: Error) => void): Instance;
saved: boolean;
saved(): boolean;
remove(callback: (err: Error) => void): Instance;
isInstance: boolean;
isPersisted: boolean;
isPersisted(): boolean;
isShell: boolean;

@@ -136,8 +567,9 @@ validate(callback: (errors: Error[]) => void);

export interface IChainFind {
find(conditions: { [property: string]: any }): IChainFind;
find(conditions: ModelMethod__FindConditions): IChainFind;
only(...args: string[]): IChainFind;
limit(limit: number): IChainFind;
offset(offset: number): IChainFind;
run(callback: (err: Error, results: Instance[]) => void): void;
count(callback: (err: Error, count: number) => void): void;
run(callback?: ModelMethod__CommonCallback): void;
count(callback: ModelMethod__CountCallback): void;
remove(callback: (err: Error) => void): void;

@@ -150,4 +582,55 @@ save(callback: (err: Error) => void): void;

get(callback: (results: Instance[]) => void): IChainFind;
}
export interface ChainFindInstanceType {
all(conditions: ModelMethod__FindConditions): IChainFind;
where(conditions: ModelMethod__FindConditions): IChainFind;
find(conditions: ModelMethod__FindConditions): IChainFind;
only(...args: string[]): IChainFind;
omit(): IChainFind;
skip(offset: number): IChainFind;
offset(offset: number): IChainFind;
order(propertyOrderDesc: string, order: string | "Z" | "A" ): IChainFind;
orderRaw(str: string, args: any[]): IChainFind;
limit(limit: number): IChainFind;
count(callback: ModelMethod__CountCallback): void;
remove(callback: (err: Error) => void): void;
run(callback?: ModelMethod__CommonCallback): void;
success(callback?: ModelMethod__CommonCallback): void;
fail(callback?: ModelMethod__CommonCallback): void;
first(callback?: ModelMethod__CommonCallback): void;
last(callback?: ModelMethod__CommonCallback): void;
each(callback: (result: Instance) => void): void;
each(): IChainFind;
eager(): IChainFind;
model: FibOrmFixedModel;
options: ChainFindOptions
}
export interface ChainFindOptions {
conditions
properties
order
driver
only
table
limit
merge
offset
exists
__eager
keys
newInstance
keyProperties
associations
}
/*

@@ -199,8 +682,10 @@ * Classes

export interface SingletonOptions {
identityCache?: any;
saveCheck?: boolean;
}
export class singleton {
static clear(key?: string): singleton;
static get(key, opts: {
identityCache?: any;
saveCheck?: boolean;
}, createCb: Function, returnCb: Function);
static get(key, opts: SingletonOptions, createCb: Function, returnCb: Function);
}

@@ -237,2 +722,5 @@

get: {
(key: string, def?: Function): any
}
//[key: string]: {

@@ -239,0 +727,0 @@ // get: (key, def) => any;

v1.4.2-postalpha / 2018-10-02
v1.4.3-postalpha.1 / 2018-10-09
==================
* typo fix.
v1.4.3 / 2018-10-03
===================
* Release v1.4.3
* code structure adjust.
* fix params passed to driver's customType.valueToProperty
* [WIP] normalize type definitions
* mv 'src/orm/src' to 'src/orm/entry'
* [README.md] little fix.
v1.4.2-postalpha / 2018-10-02
=============================
* Release v1.4.2-postalpha
* migrate from 'fib-orm'

@@ -6,0 +22,0 @@ * upgrade version of 'fib-typify'

@@ -1,33 +0,39 @@

var _ = require('lodash');
var ORMError = require("../Error");
var Settings = require("../Settings");
var Singleton = require("../Singleton");
var util = require("../Utilities");
exports.prepare = function (db, Model, associations) {
Object.defineProperty(exports, "__esModule", { value: true });
const _utils_1 = require("./_utils");
const _ = require('lodash');
const ORMError = require("../Error");
const Singleton = require("../Singleton");
const util = require("../Utilities");
/**
*
* @param db orm instance
* @param Model model
* @param associations association definitions
*/
function prepare(db, Model, associations) {
Model.extendsTo = function (name, properties, opts) {
opts = opts || {};
var assocName = opts.name || ucfirst(name);
var association = {
const assocName = opts.name || ucfirst(name);
const association = {
name: name,
table: opts.table || (Model.table + '_' + name),
table: opts.table || _utils_1.defineDefaultExtendsToTableName(Model.table, name),
reversed: opts.reversed,
autoFetch: opts.autoFetch || false,
autoFetchLimit: opts.autoFetchLimit || 2,
field: util.wrapFieldObject({
field: opts.field, model: Model, altName: Model.table
}) || util.formatField(Model, Model.table, false, false),
getAccessor: opts.getAccessor || ("get" + assocName),
setAccessor: opts.setAccessor || ("set" + assocName),
hasAccessor: opts.hasAccessor || ("has" + assocName),
delAccessor: opts.delAccessor || ("remove" + assocName)
field: util.wrapFieldObject({ field: opts.field, model: Model, altName: Model.table }) || util.formatField(Model, Model.table, false, false),
getAccessor: opts.getAccessor || _utils_1.defineAssociationAccessorMethodName('get', assocName),
setAccessor: opts.setAccessor || _utils_1.defineAssociationAccessorMethodName('set', assocName),
hasAccessor: opts.hasAccessor || _utils_1.defineAssociationAccessorMethodName('has', assocName),
delAccessor: opts.delAccessor || _utils_1.defineAssociationAccessorMethodName('remove', assocName),
model: null
};
var newproperties = _.cloneDeep(properties);
const newProperties = _.cloneDeep(properties);
for (var k in association.field) {
newproperties[k] = association.field[k];
newProperties[k] = association.field[k];
}
var modelOpts = _.extend(_.pick(opts, 'identityCache', 'autoSave', 'cascadeRemove', 'hooks', 'methods', 'validations'), {
const modelOpts = _.extend(_.pick(opts, 'identityCache', 'autoSave', 'cascadeRemove', 'hooks', 'methods', 'validations'), {
id: Object.keys(association.field),
extension: true,
});
association.model = db.define(association.table, newproperties, modelOpts);
association.model = db.define(association.table, newProperties, modelOpts);
association.model.hasOne(Model.table, Model, { extension: true, field: association.field });

@@ -62,3 +68,3 @@ associations.push(association);

options.extra = [];
if (typeof cb == "function") {
if (typeof cb === "function") {
return Model.find({}, options, cb);

@@ -70,9 +76,13 @@ }

};
};
exports.extend = function (Model, Instance, Driver, associations, opts) {
}
exports.prepare = prepare;
;
function extend(Model, Instance, Driver, associations, opts) {
for (var i = 0; i < associations.length; i++) {
extendInstance(Model, Instance, Driver, associations[i], opts);
}
};
exports.autoFetch = function (Instance, associations, opts, cb) {
}
exports.extend = extend;
;
function autoFetch(Instance, associations, opts, cb) {
if (associations.length === 0) {

@@ -91,3 +101,5 @@ return cb();

}
};
}
exports.autoFetch = autoFetch;
;
function extendInstance(Model, Instance, Driver, association, opts) {

@@ -94,0 +106,0 @@ Object.defineProperty(Instance, association.hasAccessor, {

@@ -1,23 +0,23 @@

var _ = require("lodash");
var InstanceConstructor = require("../Instance").Instance;
var Hook = require("../Hook");
var Settings = require("../Settings");
var Property = require("../Property");
var ORMError = require("../Error");
var util = require("../Utilities");
exports.prepare = function (db, Model, associations) {
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const Hook = require("../Hook");
const Settings = require("../Settings");
const Property = require("../Property");
const ORMError = require("../Error");
const util = require("../Utilities");
function prepare(db, Model, associations) {
Model.hasMany = function () {
var name, makeKey, mergeId, mergeAssocId;
var OtherModel = Model;
var props = null;
var opts = {};
let name, makeKey, mergeId, mergeAssocId;
let OtherModel = Model;
let props = null;
let opts = {};
for (var i = 0; i < arguments.length; i++) {
switch (typeof arguments[i]) {
case "string":
case 'string':
name = arguments[i];
break;
case "function":
case 'function':
OtherModel = arguments[i];
break;
case "object":
case 'object':
if (props === null) {

@@ -61,6 +61,3 @@ props = arguments[i];

// I'm not sure the next key is used..
field: util.wrapFieldObject({
field: opts.field, model: OtherModel, altName: Model.table
}) ||
util.formatField(Model, name, true, opts.reversed),
field: util.wrapFieldObject({ field: opts.field, model: OtherModel, altName: Model.table }) || util.formatField(Model, name, true, opts.reversed),
mergeTable: opts.mergeTable || (Model.table + "_" + name),

@@ -90,9 +87,13 @@ mergeId: mergeId,

};
};
exports.extend = function (Model, Instance, Driver, associations, opts, createInstance) {
}
exports.prepare = prepare;
;
function extend(Model, Instance, Driver, associations, opts, createInstance) {
for (var i = 0; i < associations.length; i++) {
extendInstance(Model, Instance, Driver, associations[i], opts, createInstance);
}
};
exports.autoFetch = function (Instance, associations, opts, cb) {
}
exports.extend = extend;
;
function autoFetch(Instance, associations, opts, cb) {
if (associations.length === 0) {

@@ -111,3 +112,5 @@ return cb();

}
};
}
exports.autoFetch = autoFetch;
;
function extendInstance(Model, Instance, Driver, association, opts, createInstance) {

@@ -448,3 +451,2 @@ if (Model.settings.get("instance.cascadeRemove")) {

}
function noOperation() {
}
function noOperation() { }

@@ -1,12 +0,23 @@

var _ = require("lodash");
var util = require("../Utilities");
var ORMError = require("../Error");
var Accessors = { "get": "get", "set": "set", "has": "has", "del": "remove" };
exports.prepare = function (Model, associations) {
Model.hasOne = function () {
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const util = require("../Utilities");
const ORMError = require("../Error");
const Accessors = {
"get": "get",
"set": "set",
"has": "has",
"del": "remove"
};
function prepare(Model, associations) {
Model.hasOne = function (assoc_name, ext_model, assoc_options) {
if (arguments[1] && !arguments[1].table) {
assoc_options = arguments[1];
ext_model = arguments[1] = null;
}
var assocName;
var assocTemplateName;
var association = {
name: Model.table,
model: Model,
name: assoc_name || Model.table,
model: ext_model || Model,
field: null,
reversed: false,

@@ -16,22 +27,13 @@ extension: false,

autoFetchLimit: 2,
required: false
required: false,
setAccessor: null,
getAccessor: null,
hasAccessor: null,
delAccessor: null
};
for (var i = 0; i < arguments.length; i++) {
switch (typeof arguments[i]) {
case "string":
association.name = arguments[i];
break;
case "function":
if (arguments[i].table) {
association.model = arguments[i];
}
break;
case "object":
association = _.extend(association, arguments[i]);
break;
}
}
association = _.extend(association, assoc_options || {});
assocName = ucfirst(association.name);
assocTemplateName = association.accessor || assocName;
if (!association.hasOwnProperty("field")) {
// if (!association.hasOwnProperty("field")) {
if (!association.field) {
association.field = util.formatField(association.model, association.name, association.required, association.reversed);

@@ -49,3 +51,4 @@ }

for (var k in Accessors) {
if (!association.hasOwnProperty(k + "Accessor")) {
// if (!association.hasOwnProperty(k + "Accessor")) {
if (!association[k + "Accessor"]) {
association[k + "Accessor"] = Accessors[k] + assocTemplateName;

@@ -107,9 +110,13 @@ }

};
};
exports.extend = function (Model, Instance, Driver, associations) {
}
exports.prepare = prepare;
;
function extend(Model, Instance, Driver, associations) {
for (var i = 0; i < associations.length; i++) {
extendInstance(Model, Instance, Driver, associations[i]);
}
};
exports.autoFetch = function (Instance, associations, opts, cb) {
}
exports.extend = extend;
;
function autoFetch(Instance, associations, opts, cb) {
if (associations.length === 0) {

@@ -128,3 +135,5 @@ return cb();

}
};
}
exports.autoFetch = autoFetch;
;
function extendInstance(Model, Instance, Driver, association) {

@@ -131,0 +140,0 @@ Object.defineProperty(Instance, association.hasAccessor, {

@@ -6,4 +6,40 @@ var _ = require("lodash");

var Promise = require("./Promise").Promise;
module.exports = ChainFind;
function ChainFind(Model, opts) {
function addChainMethod(chain, association, opts) {
chain[association.hasAccessor] = function (value) {
if (!opts.exists) {
opts.exists = [];
}
var conditions = {};
var assocIds = Object.keys(association.mergeAssocId);
var ids = association.model.id;
function mergeConditions(source) {
for (var i = 0; i < assocIds.length; i++) {
if (typeof conditions[assocIds[i]] === "undefined") {
conditions[assocIds[i]] = source[ids[i]];
}
else if (Array.isArray(conditions[assocIds[i]])) {
conditions[assocIds[i]].push(source[ids[i]]);
}
else {
conditions[assocIds[i]] = [conditions[assocIds[i]], source[ids[i]]];
}
}
}
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
mergeConditions(value[i]);
}
}
else {
mergeConditions(value);
}
opts.exists.push({
table: association.mergeTable,
link: [Object.keys(association.mergeId), association.model.id],
conditions: conditions
});
return chain;
};
}
module.exports = function ChainFind(Model, opts) {
var prepareConditions = function () {

@@ -73,2 +109,6 @@ return Utilities.transformPropertyNames(opts.conditions, opts.properties);

var chain = {
model: null,
options: null,
all: null,
where: null,
find: function () {

@@ -249,39 +289,2 @@ var cb = null;

return chain;
}
function addChainMethod(chain, association, opts) {
chain[association.hasAccessor] = function (value) {
if (!opts.exists) {
opts.exists = [];
}
var conditions = {};
var assocIds = Object.keys(association.mergeAssocId);
var ids = association.model.id;
function mergeConditions(source) {
for (var i = 0; i < assocIds.length; i++) {
if (typeof conditions[assocIds[i]] === "undefined") {
conditions[assocIds[i]] = source[ids[i]];
}
else if (Array.isArray(conditions[assocIds[i]])) {
conditions[assocIds[i]].push(source[ids[i]]);
}
else {
conditions[assocIds[i]] = [conditions[assocIds[i]], source[ids[i]]];
}
}
}
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
mergeConditions(value[i]);
}
}
else {
mergeConditions(value);
}
opts.exists.push({
table: association.mergeTable,
link: [Object.keys(association.mergeId), association.model.id],
conditions: conditions
});
return chain;
};
}
};

@@ -1,3 +0,2 @@

module.exports = ChainInstance;
function ChainInstance(chain, cb) {
module.exports = function ChainInstance(chain, cb) {
var instances = null;

@@ -14,3 +13,3 @@ var loading = false;

var promise = function (hwd, next) {
return function () {
return function (...args) {
if (!loading) {

@@ -75,2 +74,2 @@ load();

return calls;
}
};

@@ -1,4 +0,5 @@

var _ = require("lodash");
var Sync = require("sql-ddl-sync").Sync;
exports.sync = function (opts, cb) {
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const Sync = require("sql-ddl-sync").Sync;
function sync(opts, cb) {
var sync = new Sync({

@@ -29,4 +30,6 @@ driver: this,

return this;
};
exports.drop = function (opts, cb) {
}
exports.sync = sync;
;
function drop(opts, cb) {
var i, queries = [], pending;

@@ -46,2 +49,4 @@ queries.push("DROP TABLE IF EXISTS " + this.query.escapeId(opts.table));

return this;
};
}
exports.drop = drop;
;

@@ -1,27 +0,28 @@

module.exports = {
execQuery: function () {
if (arguments.length == 2) {
var query = arguments[0];
var cb = arguments[1];
}
else if (arguments.length == 3) {
var query = this.query.escape(arguments[0], arguments[1]);
var cb = arguments[2];
}
return this.execSimpleQuery(query, cb);
},
eagerQuery: function (association, opts, keys, cb) {
var desiredKey = Object.keys(association.field);
var assocKey = Object.keys(association.mergeAssocId);
var where = {};
where[desiredKey] = keys;
var query = this.query.select()
.from(association.model.table)
.select(opts.only)
.from(association.mergeTable, assocKey, opts.keys)
.select(desiredKey).as("$p")
.where(association.mergeTable, where)
.build();
this.execSimpleQuery(query, cb);
Object.defineProperty(exports, "__esModule", { value: true });
function execQuery() {
if (arguments.length == 2) {
var query = arguments[0];
var cb = arguments[1];
}
};
else if (arguments.length == 3) {
var query = this.query.escape(arguments[0], arguments[1]);
var cb = arguments[2];
}
return this.execSimpleQuery(query, cb);
}
exports.execQuery = execQuery;
function eagerQuery(association, opts, keys, cb) {
var desiredKey = Object.keys(association.field);
var assocKey = Object.keys(association.mergeAssocId);
var where = {};
where[desiredKey + ''] = keys;
var query = this.query.select()
.from(association.model.table)
.select(opts.only)
.from(association.mergeTable, assocKey, opts.keys)
.select(desiredKey).as("$p")
.where(association.mergeTable, where)
.build();
this.execSimpleQuery(query, cb);
}
exports.eagerQuery = eagerQuery;

@@ -0,1 +1,2 @@

Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");

@@ -6,3 +7,2 @@ var mysql = require("mysql");

var DDL = require("../DDL/SQL");
exports.Driver = Driver;
function Driver(config, connection, opts) {

@@ -26,2 +26,3 @@ this.dialect = 'mysql';

}
exports.Driver = Driver;
_.extend(Driver.prototype, shared, DDL);

@@ -234,3 +235,3 @@ Driver.prototype.ping = function (cb) {

if (customType && 'valueToProperty' in customType) {
value = customType.valueToProperty(value);
value = customType.valueToProperty(value, property);
}

@@ -237,0 +238,0 @@ }

@@ -0,1 +1,2 @@

Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");

@@ -6,3 +7,2 @@ var pg = require("pg");

var DDL = require("../DDL/SQL");
exports.Driver = Driver;
var switchableFunctions = {

@@ -111,2 +111,3 @@ pool: {

}
exports.Driver = Driver;
_.extend(Driver.prototype, shared, DDL);

@@ -230,3 +231,3 @@ Driver.prototype.ping = function (cb) {

if (m) {
value = { x: parseFloat(m[1], 10), y: parseFloat(m[2], 10) };
value = { x: parseFloat(m[1]), y: parseFloat(m[2]) };
}

@@ -273,3 +274,3 @@ }

if (customType && 'valueToProperty' in customType) {
value = customType.valueToProperty(value);
value = customType.valueToProperty(value, property);
}

@@ -276,0 +277,0 @@ }

@@ -257,3 +257,3 @@ var _ = require("lodash");

if (customType && 'valueToProperty' in customType) {
value = customType.valueToProperty(value);
value = customType.valueToProperty(value, property);
}

@@ -260,0 +260,0 @@ }

@@ -1,2 +0,3 @@

var codes = {
var _a;
const codes = {
QUERY_ERROR: 1,

@@ -11,26 +12,30 @@ NOT_FOUND: 2,

};
function ORMError(message, code, extras) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.message = message;
if (code) {
this.code = codes[code];
this.literalCode = code;
if (!this.code) {
throw new Error("Invalid error code: " + code);
module.exports = (_a = class ORMError extends Error {
constructor(message, code, extras) {
super();
this.name = 'ORMError';
this.message = '';
this.code = 0;
this.literalCode = '';
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.message = message;
if (code) {
this.code = codes[code];
this.literalCode = code;
if (!this.code) {
throw new Error("Invalid error code: " + code);
}
}
if (extras) {
for (let k in extras) {
this[k] = extras[k];
}
}
}
}
if (extras) {
for (var k in extras) {
this[k] = extras[k];
toString() {
return '[ORMError ' + this.literalCode + ': ' + this.message + ']';
}
}
}
ORMError.prototype = Object.create(Error.prototype);
ORMError.prototype.constructor = ORMError;
ORMError.prototype.name = 'ORMError';
ORMError.prototype.toString = function () {
return '[ORMError ' + this.literalCode + ': ' + this.message + ']';
};
ORMError.codes = codes;
module.exports = ORMError;
},
_a.codes = codes,
_a);

@@ -1,2 +0,3 @@

exports.trigger = function () {
Object.defineProperty(exports, "__esModule", { value: true });
function trigger() {
var args = Array.prototype.slice.apply(arguments);

@@ -8,4 +9,6 @@ var self = args.shift();

}
};
exports.wait = function () {
}
exports.trigger = trigger;
;
function wait() {
var args = Array.prototype.slice.apply(arguments);

@@ -25,2 +28,4 @@ var self = args.shift();

}
};
}
exports.wait = wait;
;

@@ -1,6 +0,6 @@

var Utilities = require("./Utilities");
var Property = require("./Property");
var Hook = require("./Hook");
var enforce = require("enforce");
exports.Instance = Instance;
Object.defineProperty(exports, "__esModule", { value: true });
const Utilities = require("./Utilities");
const Hook = require("./Hook");
const enforce = require("@fibjs/enforce");
// export interface Instance extends FibOrmFixedModelInstanceFn {}
function Instance(Model, opts) {

@@ -540,3 +540,3 @@ opts = opts || {};

default:
var err = new Error("Unknown parameter type '" + (typeof arg) + "' in Instance.save()");
const err = new Error("Unknown parameter type '" + (typeof arg) + "' in Instance.save()");
err.model = Model.table;

@@ -687,1 +687,2 @@ throw err;

}
exports.Instance = Instance;

@@ -1,2 +0,3 @@

exports.extend = function (Instance, Model, properties) {
Object.defineProperty(exports, "__esModule", { value: true });
function extend(Instance, Model, properties) {
for (var k in properties) {

@@ -7,3 +8,5 @@ if (properties[k].lazyload === true) {

}
};
}
exports.extend = extend;
;
function addLazyLoadProperty(name, Instance, Model, property) {

@@ -10,0 +13,0 @@ var method = ucfirst(name);

@@ -1,16 +0,17 @@

var _ = require("lodash");
var async = require("async");
var ChainFind = require("./ChainFind");
var Instance = require("./Instance").Instance;
var LazyLoad = require("./LazyLoad");
var ManyAssociation = require("./Associations/Many");
var OneAssociation = require("./Associations/One");
var ExtendAssociation = require("./Associations/Extend");
var Property = require("./Property");
var Singleton = require("./Singleton");
var Utilities = require("./Utilities");
var Validators = require("./Validators");
var ORMError = require("./Error");
var Hook = require("./Hook");
var AvailableHooks = [
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const async = require("async");
const ChainFind = require("./ChainFind");
const Instance_1 = require("./Instance");
const LazyLoad = require("./LazyLoad");
const ManyAssociation = require("./Associations/Many");
const OneAssociation = require("./Associations/One");
const ExtendAssociation = require("./Associations/Extend");
const Property = require("./Property");
const Singleton = require("./Singleton");
const Utilities = require("./Utilities");
const Validators = require("./Validators");
const ORMError = require("./Error");
const Hook = require("./Hook");
const AvailableHooks = [
"beforeCreate", "afterCreate",

@@ -23,7 +24,4 @@ "beforeSave", "afterSave",

];
exports.Model = Model;
function Model(opts) {
opts = _.defaults(opts || {}, {
keys: []
});
opts = _.defaults(opts || {}, { keys: [] });
opts.keys = Array.isArray(opts.keys) ? opts.keys : [opts.keys];

@@ -89,3 +87,3 @@ var one_associations = [];

var setupAssociations = function (instance) {
OneAssociation.extend(model, instance, opts.driver, one_associations, assoc_opts);
OneAssociation.extend(model, instance, opts.driver, one_associations);
ManyAssociation.extend(model, instance, opts.driver, many_associations, assoc_opts, createInstance);

@@ -95,3 +93,3 @@ ExtendAssociation.extend(model, instance, opts.driver, extend_associations, assoc_opts);

var pending = 2, create_err = null;
var instance = new Instance(model, {
var instance = new Instance_1.Instance(model, {
uid: inst_opts.uid,

@@ -147,3 +145,3 @@ keys: opts.keys,

};
var model = function () {
const model = function () {
var instance, i;

@@ -160,3 +158,3 @@ var data = arguments.length > 1 ? arguments : arguments[0];

else {
var err = new Error('Model requires ' + opts.keys.length + ' keys, only ' + data.length + ' were provided');
const err = new Error('Model requires ' + opts.keys.length + ' keys, only ' + data.length + ' were provided');
err.model = opts.table;

@@ -667,1 +665,2 @@ throw err;

}
exports.Model = Model;

@@ -6,3 +6,3 @@ var util = require("util");

var Query = require("sql-query");
var enforce = require("enforce");
var enforce = require("@fibjs/enforce");
var _ = require("lodash");

@@ -235,3 +235,3 @@ var Model = require("./Model").Model;

var files = _.flatten(Array.prototype.slice.apply(arguments));
var cb = function () { };
var cb = function (err) { };
if (typeof files[files.length - 1] == "function") {

@@ -238,0 +238,0 @@ cb = files.pop();

@@ -1,3 +0,4 @@

var _ = require('lodash');
var ORMError = require("./Error");
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require('lodash');
const ORMError = require("./Error");
var KNOWN_TYPES = [

@@ -7,3 +8,3 @@ "text", "number", "integer", "boolean", "date", "enum", "object",

];
exports.normalize = function (opts) {
function normalize(opts) {
if (typeof opts.prop === "function") {

@@ -65,2 +66,4 @@ switch (opts.prop.name) {

return opts.prop;
};
}
exports.normalize = normalize;
;

@@ -1,3 +0,4 @@

var _ = require('lodash');
var default_settings = {
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require('lodash');
const default_settings = {
properties: {

@@ -40,3 +41,3 @@ primary_key: "id",

get: function (key, def) {
var v = get(key, def, settings);
const v = get(key, def, settings);
if (v instanceof Function) {

@@ -50,3 +51,3 @@ return v;

unset: function () {
for (var i = 0; i < arguments.length; i++) {
for (let i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === "string") {

@@ -61,3 +62,3 @@ unset(arguments[i], settings);

function set(key, value, obj) {
var p = key.indexOf(".");
const p = key.indexOf(".");
if (p === -1) {

@@ -72,3 +73,3 @@ return obj[key] = value;

function get(key, def, obj) {
var p = key.indexOf(".");
const p = key.indexOf(".");
if (p === -1) {

@@ -86,3 +87,3 @@ if (key === '*') {

function unset(key, obj) {
var p = key.indexOf(".");
const p = key.indexOf(".");
if (p === -1) {

@@ -89,0 +90,0 @@ if (key === '*') {

@@ -1,3 +0,4 @@

var map = {};
exports.clear = function (key) {
Object.defineProperty(exports, "__esModule", { value: true });
let map = {};
function clear(key) {
if (typeof key === "string") {

@@ -10,4 +11,6 @@ delete map[key];

return this;
};
exports.get = function (key, opts, createCb, returnCb) {
}
exports.clear = clear;
;
function get(key, opts, createCb, returnCb) {
if (opts && opts.identityCache === false) {

@@ -37,2 +40,4 @@ return createCb(returnCb);

});
};
}
exports.get = get;
;

@@ -1,2 +0,3 @@

var _ = require('lodash');
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require('lodash');
/**

@@ -19,3 +20,3 @@ * Order should be a String (with the property name assumed ascending)

*/
exports.standardizeOrder = function (order) {
function standardizeOrder(order) {
if (typeof order === "string") {

@@ -27,3 +28,4 @@ if (order[0] === "-") {

}
var new_order = [], minus;
const new_order = [];
let minus;
for (var i = 0; i < order.length; i++) {

@@ -46,3 +48,5 @@ minus = (order[i][0] === "-");

return new_order;
};
}
exports.standardizeOrder = standardizeOrder;
;
/**

@@ -57,3 +61,3 @@ * Operations

*/
exports.checkConditions = function (conditions, one_associations) {
function checkConditions(conditions, one_associations) {
var k, i, j;

@@ -104,3 +108,5 @@ // A)

return conditions;
};
}
exports.checkConditions = checkConditions;
;
/**

@@ -110,3 +116,3 @@ * Gets all the values within an object or array, optionally

*/
exports.values = function (obj, keys) {
function values(obj, keys) {
var i, k, vals = [];

@@ -131,7 +137,9 @@ if (keys) {

return vals;
};
}
exports.values = values;
;
// Qn: is Zero a valid value for a FK column?
// Why? Well I've got a pre-existing database that started all its 'serial' IDs at zero...
// Answer: hasValues() is only used in hasOne association, so it's probably ok...
exports.hasValues = function (obj, keys) {
function hasValues(obj, keys) {
for (var i = 0; i < keys.length; i++) {

@@ -142,4 +150,6 @@ if (!obj[keys[i]] && obj[keys[i]] !== 0)

return true;
};
exports.populateConditions = function (model, fields, source, target, overwrite) {
}
exports.hasValues = hasValues;
;
function populateConditions(model, fields, source, target, overwrite) {
for (var i = 0; i < model.id.length; i++) {

@@ -156,9 +166,13 @@ if (typeof target[fields[i]] === 'undefined' || overwrite !== false) {

}
};
exports.getConditions = function (model, fields, from) {
}
exports.populateConditions = populateConditions;
;
function getConditions(model, fields, from) {
var conditions = {};
exports.populateConditions(model, fields, from, conditions);
populateConditions(model, fields, from, conditions);
return conditions;
};
exports.wrapFieldObject = function (params) {
}
exports.getConditions = getConditions;
;
function wrapFieldObject(params) {
if (!params.field) {

@@ -193,5 +207,14 @@ var assoc_key = params.model.settings.get("properties.association_key");

return newObj;
};
exports.formatField = function (model, name, required, reversed) {
var fields = {}, field_opts, field_name;
}
exports.wrapFieldObject = wrapFieldObject;
;
/**
*
* @param model related Model
* @param name field name
* @param required is field required for relationship
* @param reversed is model is reversed in relationship
*/
function formatField(model, name, required, reversed) {
let fields = {}, field_opts, field_name;
var keys = model.id;

@@ -237,6 +260,8 @@ var assoc_key = model.settings.get("properties.association_key");

return fields;
};
}
exports.formatField = formatField;
;
// If the parent associations key is `serial`, the join tables
// key should be changed to `integer`.
exports.convertPropToJoinKeyProp = function (props, opts) {
function convertPropToJoinKeyProp(props, opts) {
var prop;

@@ -257,4 +282,5 @@ for (var k in props) {

return props;
};
exports.getRealPath = function (path_str, stack_index) {
}
exports.convertPropToJoinKeyProp = convertPropToJoinKeyProp;
function getRealPath(path_str, stack_index) {
var path = require("path"); // for now, load here (only when needed)

@@ -281,4 +307,6 @@ var cwd = process.cwd();

return path_str;
};
exports.transformPropertyNames = function (dataIn, properties) {
}
exports.getRealPath = getRealPath;
;
function transformPropertyNames(dataIn, properties) {
var k, prop;

@@ -296,7 +324,9 @@ var dataOut = {};

return dataOut;
};
exports.transformOrderPropertyNames = function (order, properties) {
}
exports.transformPropertyNames = transformPropertyNames;
;
function transformOrderPropertyNames(order, properties) {
if (!order)
return order;
var i, item;
var item;
var newOrder = JSON.parse(JSON.stringify(order));

@@ -320,4 +350,5 @@ // Rename order properties according to mapsTo

return newOrder;
};
exports.renameDatastoreFieldsToPropertyNames = function (data, fieldToPropertyMap) {
}
exports.transformOrderPropertyNames = transformOrderPropertyNames;
function renameDatastoreFieldsToPropertyNames(data, fieldToPropertyMap) {
var k, prop;

@@ -332,2 +363,3 @@ for (k in data) {

return data;
};
}
exports.renameDatastoreFieldsToPropertyNames = renameDatastoreFieldsToPropertyNames;

@@ -1,13 +0,12 @@

var enforce = require("enforce");
var util = require("util");
var validators = {
required: enforce.required,
notEmptyString: enforce.notEmptyString,
rangeNumber: enforce.ranges.number,
rangeLength: enforce.ranges.length,
insideList: enforce.lists.inside,
outsideList: enforce.lists.outside,
password: enforce.security.password,
patterns: enforce.patterns
};
Object.defineProperty(exports, "__esModule", { value: true });
const enforce = require("@fibjs/enforce");
const util = require("util");
exports.required = enforce.required;
exports.notEmptyString = enforce.notEmptyString;
exports.rangeNumber = enforce.ranges.number;
exports.rangeLength = enforce.ranges.length;
exports.insideList = enforce.lists.inside;
exports.outsideList = enforce.lists.outside;
exports.password = enforce.security.password;
exports.patterns = enforce.patterns;
/**

@@ -18,3 +17,3 @@ * Check if a value is the same as a value

**/
validators.equalToProperty = function (name, msg) {
function equalToProperty(name, msg) {
return function (v, next) {

@@ -26,3 +25,5 @@ if (v === this[name]) {

};
};
}
exports.equalToProperty = equalToProperty;
;
/**

@@ -42,5 +43,5 @@ * Check if a property is unique in the collection.

**/
validators.unique = function () {
function unique(opts = {}) {
var arg, k;
var msg = null, opts = {};
var msg = null;
for (k in arguments) {

@@ -60,3 +61,3 @@ arg = arguments[k];

}
//Cannot process on database engines which don't support SQL syntax
// Cannot process on database engines which don't support SQL syntax
if (!ctx.driver.isSql) {

@@ -103,3 +104,4 @@ return next('not-supported');

};
};
module.exports = validators;
}
exports.unique = unique;
;
{
"name": "@fxjs/orm",
"version": "1.4.2-postalpha.2",
"version": "1.4.3-postalpha.1",
"description": "Object Relational Mapping for fibjs",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc