├── .codeclimate.yml ├── .gitignore ├── .npmignore ├── .travis.yml ├── .vscode ├── extensions.json ├── settings.json └── tasks.json ├── LICENSE ├── README-v3.md ├── README.md ├── dist ├── lib │ ├── builtin.d.ts │ ├── builtin.js │ ├── constants.d.ts │ ├── constants.js │ ├── contracts │ │ ├── Driver.d.ts │ │ ├── Driver.js │ │ ├── DriverProvider.d.ts │ │ ├── DriverProvider.js │ │ ├── FactoryBuilder.d.ts │ │ ├── FactoryBuilder.js │ │ ├── FactoryManager.d.ts │ │ ├── FactoryManager.js │ │ ├── MemoryDataSource.d.ts │ │ ├── MemoryDataSource.js │ │ ├── MemoryDataSourceProvider.d.ts │ │ ├── MemoryDataSourceProvider.js │ │ ├── MomentProvider.d.ts │ │ ├── MomentProvider.js │ │ ├── QueryLog.d.ts │ │ └── QueryLog.js │ ├── data │ │ ├── DataBuffer.d.ts │ │ ├── DataBuffer.js │ │ ├── DataCollector.d.ts │ │ ├── DataCollector.js │ │ ├── DataConditionMatcher.d.ts │ │ └── DataConditionMatcher.js │ ├── definitions │ │ ├── data │ │ │ ├── IDataBuffer.d.ts │ │ │ ├── IDataBuffer.js │ │ │ ├── IDataCollector.d.ts │ │ │ ├── IDataCollector.js │ │ │ ├── IDataReader.d.ts │ │ │ └── IDataReader.js │ │ ├── driver │ │ │ ├── IExecutor.d.ts │ │ │ ├── IExecutor.js │ │ │ ├── IExecutorFactory.d.ts │ │ │ └── IExecutorFactory.js │ │ ├── factory │ │ │ ├── IFactoryDefinition.d.ts │ │ │ └── IFactoryDefinition.js │ │ ├── features │ │ │ ├── IEventFeature.d.ts │ │ │ ├── IEventFeature.js │ │ │ ├── IFeature.d.ts │ │ │ ├── IFeature.js │ │ │ ├── IFillableFeature.d.ts │ │ │ ├── IFillableFeature.js │ │ │ ├── IQueryFeature.d.ts │ │ │ ├── IQueryFeature.js │ │ │ ├── IRecordExecutor.d.ts │ │ │ ├── IRecordExecutor.js │ │ │ ├── IRecordManager.d.ts │ │ │ ├── IRecordManager.js │ │ │ ├── IRelationFeature.d.ts │ │ │ ├── IRelationFeature.js │ │ │ ├── ISerializationFeature.d.ts │ │ │ ├── ISerializationFeature.js │ │ │ ├── ISettingFeature.d.ts │ │ │ ├── ISettingFeature.js │ │ │ ├── ISoftDeletesFeature.d.ts │ │ │ ├── ISoftDeletesFeature.js │ │ │ ├── ITimestampsFeature.d.ts │ │ │ └── ITimestampsFeature.js │ │ ├── model │ │ │ ├── IModel.d.ts │ │ │ ├── IModel.js │ │ │ ├── IModelEvent.d.ts │ │ │ ├── IModelEvent.js │ │ │ ├── IModelFillable.d.ts │ │ │ ├── IModelFillable.js │ │ │ ├── IModelRecord.d.ts │ │ │ ├── IModelRecord.js │ │ │ ├── IModelRelation.d.ts │ │ │ ├── IModelRelation.js │ │ │ ├── IModelSerialization.d.ts │ │ │ ├── IModelSerialization.js │ │ │ ├── IModelSoftDeletes.d.ts │ │ │ ├── IModelSoftDeletes.js │ │ │ ├── IModelTimestamps.d.ts │ │ │ └── IModelTimestamps.js │ │ ├── query-builders │ │ │ ├── IConditionMatcher.d.ts │ │ │ ├── IConditionMatcher.js │ │ │ ├── IConvention.d.ts │ │ │ ├── IConvention.js │ │ │ ├── IQueryBuilder.d.ts │ │ │ ├── IQueryBuilder.js │ │ │ ├── IQueryBuilderFactory.d.ts │ │ │ ├── IQueryBuilderFactory.js │ │ │ ├── IQueryBuilderHandler.d.ts │ │ │ ├── IQueryBuilderHandler.js │ │ │ ├── IQueryExecutor.d.ts │ │ │ └── IQueryExecutor.js │ │ ├── query-grammars │ │ │ ├── IAdvancedQuery.d.ts │ │ │ ├── IAdvancedQuery.js │ │ │ ├── IBasicConditionQuery.d.ts │ │ │ ├── IBasicConditionQuery.js │ │ │ ├── IBasicQuery.d.ts │ │ │ ├── IBasicQuery.js │ │ │ ├── IConditionQuery.d.ts │ │ │ ├── IConditionQuery.js │ │ │ ├── IExecuteQuery.d.ts │ │ │ ├── IExecuteQuery.js │ │ │ ├── IQuery.d.ts │ │ │ ├── IQuery.js │ │ │ ├── IRelationQuery.d.ts │ │ │ └── IRelationQuery.js │ │ ├── relations │ │ │ ├── IBelongsToManyRelationship.d.ts │ │ │ ├── IBelongsToManyRelationship.js │ │ │ ├── IBelongsToRelationship.d.ts │ │ │ ├── IBelongsToRelationship.js │ │ │ ├── IHasManyRelationship.d.ts │ │ │ ├── IHasManyRelationship.js │ │ │ ├── IHasOneRelationship.d.ts │ │ │ ├── IHasOneRelationship.js │ │ │ ├── IManyToMany.d.ts │ │ │ ├── IManyToMany.js │ │ │ ├── IMorphManyRelationship.d.ts │ │ │ ├── IMorphManyRelationship.js │ │ │ ├── IMorphOneRelationship.d.ts │ │ │ ├── IMorphOneRelationship.js │ │ │ ├── IMorphToRelationship.d.ts │ │ │ ├── IMorphToRelationship.js │ │ │ ├── IPivotOptions.d.ts │ │ │ ├── IPivotOptions.js │ │ │ ├── IRelationData.d.ts │ │ │ ├── IRelationData.js │ │ │ ├── IRelationDataBucket.d.ts │ │ │ ├── IRelationDataBucket.js │ │ │ ├── IRelationship.d.ts │ │ │ ├── IRelationship.js │ │ │ ├── IRelationshipFactory.d.ts │ │ │ └── IRelationshipFactory.js │ │ └── utils │ │ │ ├── IClassSetting.d.ts │ │ │ └── IClassSetting.js │ ├── drivers │ │ ├── DriverBase.d.ts │ │ ├── DriverBase.js │ │ ├── ExecutorBase.d.ts │ │ ├── ExecutorBase.js │ │ ├── QueryLogBase.d.ts │ │ ├── QueryLogBase.js │ │ ├── Record.d.ts │ │ ├── Record.js │ │ ├── RecordConditionMatcher.d.ts │ │ ├── RecordConditionMatcher.js │ │ ├── RecordConditionMatcherFactory.d.ts │ │ ├── RecordConditionMatcherFactory.js │ │ ├── RecordDataReader.d.ts │ │ ├── RecordDataReader.js │ │ ├── RecordDataSourceBase.d.ts │ │ ├── RecordDataSourceBase.js │ │ ├── RecordExecutorBase.d.ts │ │ ├── RecordExecutorBase.js │ │ ├── RecordManager.d.ts │ │ ├── RecordManager.js │ │ ├── RecordManagerBase.d.ts │ │ ├── RecordManagerBase.js │ │ └── memory │ │ │ ├── MemoryDataSource.d.ts │ │ │ ├── MemoryDataSource.js │ │ │ ├── MemoryDriver.d.ts │ │ │ ├── MemoryDriver.js │ │ │ ├── MemoryExecutorFactory.d.ts │ │ │ ├── MemoryExecutorFactory.js │ │ │ ├── MemoryQueryBuilder.d.ts │ │ │ ├── MemoryQueryBuilder.js │ │ │ ├── MemoryQueryBuilderFactory.d.ts │ │ │ ├── MemoryQueryBuilderFactory.js │ │ │ ├── MemoryQueryBuilderHandler.d.ts │ │ │ ├── MemoryQueryBuilderHandler.js │ │ │ ├── MemoryQueryExecutor.d.ts │ │ │ ├── MemoryQueryExecutor.js │ │ │ ├── MemoryQueryLog.d.ts │ │ │ ├── MemoryQueryLog.js │ │ │ ├── MemoryRecordExecutor.d.ts │ │ │ └── MemoryRecordExecutor.js │ ├── errors │ │ ├── NotFoundError.d.ts │ │ ├── NotFoundError.js │ │ ├── RelationNotDefinedError.d.ts │ │ ├── RelationNotDefinedError.js │ │ ├── RelationNotFoundInNewInstanceError.d.ts │ │ └── RelationNotFoundInNewInstanceError.js │ ├── facades │ │ ├── container.d.ts │ │ ├── container.js │ │ └── global │ │ │ ├── DriverProviderFacade.d.ts │ │ │ ├── DriverProviderFacade.js │ │ │ ├── FactoryFacade.d.ts │ │ │ ├── FactoryFacade.js │ │ │ ├── MemoryDataSourceProviderFacade.d.ts │ │ │ ├── MemoryDataSourceProviderFacade.js │ │ │ ├── MomentProviderFacade.d.ts │ │ │ ├── MomentProviderFacade.js │ │ │ ├── QueryLogFacade.d.ts │ │ │ └── QueryLogFacade.js │ ├── factory │ │ ├── FactoryBuilder.d.ts │ │ ├── FactoryBuilder.js │ │ ├── FactoryManager.d.ts │ │ └── FactoryManager.js │ ├── features │ │ ├── EventFeature.d.ts │ │ ├── EventFeature.js │ │ ├── FeatureBase.d.ts │ │ ├── FeatureBase.js │ │ ├── FillableFeature.d.ts │ │ ├── FillableFeature.js │ │ ├── QueryFeature.d.ts │ │ ├── QueryFeature.js │ │ ├── RelationFeature.d.ts │ │ ├── RelationFeature.js │ │ ├── SerializationFeature.d.ts │ │ ├── SerializationFeature.js │ │ ├── SettingFeature.d.ts │ │ ├── SettingFeature.js │ │ ├── SoftDeletesFeature.d.ts │ │ ├── SoftDeletesFeature.js │ │ ├── TimestampsFeature.d.ts │ │ ├── TimestampsFeature.js │ │ └── mixin │ │ │ ├── EventPublicApi.d.ts │ │ │ ├── EventPublicApi.js │ │ │ ├── FillablePublicApi.d.ts │ │ │ ├── FillablePublicApi.js │ │ │ ├── RecordManagerPublicApi.d.ts │ │ │ ├── RecordManagerPublicApi.js │ │ │ ├── RelationPublicApi.d.ts │ │ │ ├── RelationPublicApi.js │ │ │ ├── SerializationPublicApi.d.ts │ │ │ ├── SerializationPublicApi.js │ │ │ ├── SoftDeletesPublicApi.d.ts │ │ │ ├── SoftDeletesPublicApi.js │ │ │ ├── TimestampsPublicApi.d.ts │ │ │ └── TimestampsPublicApi.js │ ├── index.d.ts │ ├── index.js │ ├── model │ │ ├── Model.d.ts │ │ ├── Model.js │ │ ├── ModelEvent.d.ts │ │ ├── ModelEvent.js │ │ ├── ModelProxyHandler.d.ts │ │ └── ModelProxyHandler.js │ ├── providers │ │ ├── DriverProvider.d.ts │ │ ├── DriverProvider.js │ │ ├── MemoryDataSourceProvider.d.ts │ │ ├── MemoryDataSourceProvider.js │ │ ├── MomentProvider.d.ts │ │ └── MomentProvider.js │ ├── query-builders │ │ ├── QueryBuilder.d.ts │ │ ├── QueryBuilder.js │ │ ├── QueryBuilderHandlerBase.d.ts │ │ ├── QueryBuilderHandlerBase.js │ │ ├── mixin │ │ │ ├── AdvancedQuery.d.ts │ │ │ ├── AdvancedQuery.js │ │ │ ├── ConditionQuery.d.ts │ │ │ ├── ConditionQuery.js │ │ │ ├── ExecuteQuery.d.ts │ │ │ ├── ExecuteQuery.js │ │ │ ├── Query.d.ts │ │ │ ├── Query.js │ │ │ ├── RelationQuery.d.ts │ │ │ └── RelationQuery.js │ │ └── shared │ │ │ ├── BasicQuery.d.ts │ │ │ ├── BasicQuery.js │ │ │ ├── BasicQueryConverter.d.ts │ │ │ ├── BasicQueryConverter.js │ │ │ ├── ConditionQueryHandler.d.ts │ │ │ ├── ConditionQueryHandler.js │ │ │ ├── DefaultConvention.d.ts │ │ │ ├── DefaultConvention.js │ │ │ ├── ExecutorUtils.d.ts │ │ │ ├── ExecutorUtils.js │ │ │ ├── Operator.d.ts │ │ │ ├── Operator.js │ │ │ ├── QueryCondition.d.ts │ │ │ └── QueryCondition.js │ ├── query-log │ │ ├── FlipFlopQueryLog.d.ts │ │ └── FlipFlopQueryLog.js │ ├── relations │ │ ├── RelationData.d.ts │ │ ├── RelationData.js │ │ ├── RelationDataBucket.d.ts │ │ ├── RelationDataBucket.js │ │ ├── RelationDefinitionFinder.d.ts │ │ ├── RelationDefinitionFinder.js │ │ ├── RelationUtilities.d.ts │ │ ├── RelationUtilities.js │ │ ├── Relationship.d.ts │ │ ├── Relationship.js │ │ ├── RelationshipFactory.d.ts │ │ ├── RelationshipFactory.js │ │ ├── RelationshipType.d.ts │ │ ├── RelationshipType.js │ │ └── relationships │ │ │ ├── BelongsTo.d.ts │ │ │ ├── BelongsTo.js │ │ │ ├── BelongsToMany.d.ts │ │ │ ├── BelongsToMany.js │ │ │ ├── HasMany.d.ts │ │ │ ├── HasMany.js │ │ │ ├── HasOne.d.ts │ │ │ ├── HasOne.js │ │ │ ├── HasOneOrMany.d.ts │ │ │ ├── HasOneOrMany.js │ │ │ ├── ManyToMany.d.ts │ │ │ ├── ManyToMany.js │ │ │ ├── MorphMany.d.ts │ │ │ ├── MorphMany.js │ │ │ ├── MorphOne.d.ts │ │ │ ├── MorphOne.js │ │ │ ├── MorphTo.d.ts │ │ │ ├── MorphTo.js │ │ │ ├── executors │ │ │ ├── HasManyExecutor.d.ts │ │ │ ├── HasManyExecutor.js │ │ │ ├── HasOneExecutor.d.ts │ │ │ ├── HasOneExecutor.js │ │ │ ├── HasOneOrManyExecutor.d.ts │ │ │ ├── HasOneOrManyExecutor.js │ │ │ ├── MorphOneOrManyExecutor.d.ts │ │ │ └── MorphOneOrManyExecutor.js │ │ │ └── pivot │ │ │ ├── PivotModel.d.ts │ │ │ └── PivotModel.js │ └── util │ │ ├── ClassSetting.d.ts │ │ ├── ClassSetting.js │ │ ├── PrototypeManager.d.ts │ │ ├── PrototypeManager.js │ │ ├── SettingType.d.ts │ │ ├── SettingType.js │ │ ├── accessors.d.ts │ │ ├── accessors.js │ │ ├── factory.d.ts │ │ ├── factory.js │ │ ├── functions.d.ts │ │ ├── functions.js │ │ ├── helpers.d.ts │ │ ├── helpers.js │ │ ├── isPromise.d.ts │ │ └── isPromise.js └── test │ ├── _integration │ ├── model │ │ ├── ModelEvent.integration.test.d.ts │ │ ├── ModelEvent.integration.test.js │ │ ├── ModelFillable.integration.test.d.ts │ │ ├── ModelFillable.integration.test.js │ │ ├── ModelSerialization.integration.test.d.ts │ │ └── ModelSerialization.integration.test.js │ └── relation │ │ ├── BelongsToMany.softDeletes.test.d.ts │ │ ├── BelongsToMany.softDeletes.test.js │ │ ├── BelongsToMany.test.d.ts │ │ ├── BelongsToMany.test.js │ │ ├── BelongsToMany.timestamps.test.d.ts │ │ ├── BelongsToMany.timestamps.test.js │ │ ├── HasMany.test.d.ts │ │ ├── HasMany.test.js │ │ ├── HasOne.test.d.ts │ │ ├── HasOne.test.js │ │ ├── ManyToMany.PivotDefinition.test.d.ts │ │ ├── ManyToMany.PivotDefinition.test.js │ │ ├── MorphMany.test.d.ts │ │ ├── MorphMany.test.js │ │ ├── MorphOne.test.d.ts │ │ └── MorphOne.test.js │ ├── _syntax │ ├── Factory.test.d.ts │ └── Factory.test.js │ ├── data │ ├── DataBuffer.test.d.ts │ ├── DataBuffer.test.js │ ├── DataCollector.test.d.ts │ ├── DataCollector.test.js │ ├── DataConditionMatcher.test.d.ts │ └── DataConditionMatcher.test.js │ ├── drivers │ ├── DriverBase.test.d.ts │ ├── DriverBase.test.js │ ├── ExecutorBase.test.d.ts │ ├── ExecutorBase.test.js │ ├── QueryLogBase.test.d.ts │ ├── QueryLogBase.test.js │ ├── Record.test.d.ts │ ├── Record.test.js │ ├── RecordConditionMatcher.test.d.ts │ ├── RecordConditionMatcher.test.js │ ├── RecordConditionMatcherFactory.test.d.ts │ ├── RecordConditionMatcherFactory.test.js │ ├── RecordDataReader.test.d.ts │ ├── RecordDataReader.test.js │ ├── RecordDataSourceBase.test.d.ts │ ├── RecordDataSourceBase.test.js │ ├── RecordExecutorBase.test.d.ts │ ├── RecordExecutorBase.test.js │ ├── RecordManager.test.d.ts │ ├── RecordManager.test.js │ ├── RecordManagerBase.test.d.ts │ ├── RecordManagerBase.test.js │ └── memory │ │ ├── MemoryDataSource.test.d.ts │ │ ├── MemoryDataSource.test.js │ │ ├── MemoryExecutorFactory.test.d.ts │ │ ├── MemoryExecutorFactory.test.js │ │ ├── MemoryQueryBuilder.test.d.ts │ │ ├── MemoryQueryBuilder.test.js │ │ ├── MemoryQueryBuilderFactory.test.d.ts │ │ ├── MemoryQueryBuilderFactory.test.js │ │ ├── MemoryQueryBuilderHandler.test.d.ts │ │ ├── MemoryQueryBuilderHandler.test.js │ │ ├── MemoryQueryExecutor.test.d.ts │ │ ├── MemoryQueryExecutor.test.js │ │ ├── MemoryQueryLog.test.d.ts │ │ ├── MemoryQueryLog.test.js │ │ ├── MemoryRecordExecutor.test.d.ts │ │ └── MemoryRecordExecutor.test.js │ ├── facades │ ├── container.test.d.ts │ ├── container.test.js │ └── global │ │ ├── EloquentDriverProviderFacade.test.d.ts │ │ ├── EloquentDriverProviderFacade.test.js │ │ ├── FactoryFacade.test.d.ts │ │ ├── FactoryFacade.test.js │ │ ├── MemoryDataSourceProviderFacade.test.d.ts │ │ ├── MemoryDataSourceProviderFacade.test.js │ │ ├── MomentProviderFacade.test.d.ts │ │ ├── MomentProviderFacade.test.js │ │ ├── QueryLogFacade.test.d.ts │ │ └── QueryLogFacade.test.js │ ├── factory │ ├── FactoryBuilder.test.d.ts │ ├── FactoryBuilder.test.js │ ├── FactoryManager.test.d.ts │ └── FactoryManager.test.js │ ├── features │ ├── EventFeature.test.d.ts │ ├── EventFeature.test.js │ ├── FeatureBase.test.d.ts │ ├── FeatureBase.test.js │ ├── FillableFeature.test.d.ts │ ├── FillableFeature.test.js │ ├── QueryFeature.test.d.ts │ ├── QueryFeature.test.js │ ├── RelationFeature.test.d.ts │ ├── RelationFeature.test.js │ ├── SerializationFeature.test.d.ts │ ├── SerializationFeature.test.js │ ├── SettingFeature.test.d.ts │ ├── SettingFeature.test.js │ ├── SoftDeletesFeature.test.d.ts │ ├── SoftDeletesFeature.test.js │ ├── TimestampsFeature.test.d.ts │ ├── TimestampsFeature.test.js │ └── mixin │ │ ├── EventPublicApi.test.d.ts │ │ ├── EventPublicApi.test.js │ │ ├── FillablePublicApi.test.d.ts │ │ ├── FillablePublicApi.test.js │ │ ├── RecordManagerPublicApi.test.d.ts │ │ ├── RecordManagerPublicApi.test.js │ │ ├── RelationPublicApi.test.d.ts │ │ ├── RelationPublicApi.test.js │ │ ├── SerializationPublicApi.test.d.ts │ │ ├── SerializationPublicApi.test.js │ │ ├── SoftDeletesPublicApi.test.d.ts │ │ ├── SoftDeletesPublicApi.test.js │ │ ├── TimestampsPublicApi.test.d.ts │ │ └── TimestampsPublicApi.test.js │ ├── model │ ├── Model.test.d.ts │ ├── Model.test.js │ ├── ModelProxyHandler.test.d.ts │ └── ModelProxyHandler.test.js │ ├── providers │ ├── DriverProvider.test.d.ts │ ├── DriverProvider.test.js │ ├── MemoryDataSourceProvider.test.d.ts │ ├── MemoryDataSourceProvider.test.js │ ├── MomentProvider.test.d.ts │ └── MomentProvider.test.js │ ├── query-builders │ ├── QueryBuilder.test.d.ts │ ├── QueryBuilder.test.js │ ├── QueryBuilderHandlerBase.test.d.ts │ ├── QueryBuilderHandlerBase.test.js │ ├── mixin │ │ ├── AdvancedQuery.test.d.ts │ │ ├── AdvancedQuery.test.js │ │ ├── ConditionQuery.test.d.ts │ │ ├── ConditionQuery.test.js │ │ ├── ExecuteQuery.test.d.ts │ │ ├── ExecuteQuery.test.js │ │ ├── Query.test.d.ts │ │ ├── Query.test.js │ │ ├── RelationQuery.test.d.ts │ │ └── RelationQuery.test.js │ └── shared │ │ ├── BasicQuery.test.d.ts │ │ ├── BasicQuery.test.js │ │ ├── BasicQueryConverter.test.d.ts │ │ ├── BasicQueryConverter.test.js │ │ ├── ConditionQueryHandler.test.d.ts │ │ ├── ConditionQueryHandler.test.js │ │ ├── DefaultConvention.test.d.ts │ │ ├── DefaultConvention.test.js │ │ ├── ExecutorUtils.test.d.ts │ │ ├── ExecutorUtils.test.js │ │ ├── QueryCondition.test.d.ts │ │ └── QueryCondition.test.js │ ├── query-log │ ├── FlipFlopQueryLog.test.d.ts │ └── FlipFlopQueryLog.test.js │ ├── relations │ ├── RelationData.test.d.ts │ ├── RelationData.test.js │ ├── RelationDataBucket.test.d.ts │ ├── RelationDataBucket.test.js │ ├── RelationDenifitionFinder.test.d.ts │ ├── RelationDenifitionFinder.test.js │ ├── RelationUtilities.test.d.ts │ ├── RelationUtilities.test.js │ ├── Relationship.test.d.ts │ ├── Relationship.test.js │ ├── RelationshipFactory.test.d.ts │ ├── RelationshipFactory.test.js │ └── relationships │ │ ├── BelongsTo.test.d.ts │ │ ├── BelongsTo.test.js │ │ ├── BelongsToMany.test.d.ts │ │ ├── BelongsToMany.test.js │ │ ├── HasMany.test.d.ts │ │ ├── HasMany.test.js │ │ ├── HasOne.test.d.ts │ │ ├── HasOne.test.js │ │ ├── HasOneOrMany.test.d.ts │ │ ├── HasOneOrMany.test.js │ │ ├── ManyToMany.test.d.ts │ │ ├── ManyToMany.test.js │ │ ├── MorphMany.test.d.ts │ │ ├── MorphMany.test.js │ │ ├── MorphOne.test.d.ts │ │ ├── MorphOne.test.js │ │ ├── MorphTo.test.d.ts │ │ ├── MorphTo.test.js │ │ ├── executors │ │ ├── HasManyExecutor.test.d.ts │ │ ├── HasManyExecutor.test.js │ │ ├── HasOneExecutor.test.d.ts │ │ ├── HasOneExecutor.test.js │ │ ├── HasOneOrManyExecutor.test.d.ts │ │ ├── HasOneOrManyExecutor.test.js │ │ ├── MorphOneOrManyExecutor.test.d.ts │ │ └── MorphOneOrManyExecutor.test.js │ │ └── pivot │ │ ├── PivotModel.test.d.ts │ │ └── PivotModel.test.js │ └── util │ ├── ClassSetting.test.d.ts │ ├── ClassSetting.test.js │ ├── PrototypeManager.test.d.ts │ ├── PrototypeManager.test.js │ ├── SettingType.test.d.ts │ ├── SettingType.test.js │ ├── factory.test.d.ts │ ├── factory.test.js │ ├── functions.test.d.ts │ ├── functions.test.js │ ├── helpers.test.d.ts │ ├── helpers.test.js │ ├── isPromise.test.d.ts │ └── isPromise.test.js ├── lib ├── builtin.ts ├── constants.ts ├── contracts │ ├── Driver.ts │ ├── DriverProvider.ts │ ├── FactoryBuilder.ts │ ├── FactoryManager.ts │ ├── MemoryDataSource.ts │ ├── MemoryDataSourceProvider.ts │ ├── MomentProvider.ts │ └── QueryLog.ts ├── data │ ├── DataBuffer.ts │ ├── DataCollector.ts │ └── DataConditionMatcher.ts ├── definitions │ ├── collect.js │ │ └── index.d.ts │ ├── data │ │ ├── IDataBuffer.ts │ │ ├── IDataCollector.ts │ │ └── IDataReader.ts │ ├── driver │ │ ├── IExecutor.ts │ │ └── IExecutorFactory.ts │ ├── factory │ │ └── IFactoryDefinition.ts │ ├── features │ │ ├── IEventFeature.ts │ │ ├── IFeature.ts │ │ ├── IFillableFeature.ts │ │ ├── IQueryFeature.ts │ │ ├── IRecordExecutor.ts │ │ ├── IRecordManager.ts │ │ ├── IRelationFeature.ts │ │ ├── ISerializationFeature.ts │ │ ├── ISettingFeature.ts │ │ ├── ISoftDeletesFeature.ts │ │ └── ITimestampsFeature.ts │ ├── model │ │ ├── IModel.ts │ │ ├── IModelEvent.ts │ │ ├── IModelFillable.ts │ │ ├── IModelRecord.ts │ │ ├── IModelRelation.ts │ │ ├── IModelSerialization.ts │ │ ├── IModelSoftDeletes.ts │ │ └── IModelTimestamps.ts │ ├── query-builders │ │ ├── IConditionMatcher.ts │ │ ├── IConvention.ts │ │ ├── IQueryBuilder.ts │ │ ├── IQueryBuilderFactory.ts │ │ ├── IQueryBuilderHandler.ts │ │ └── IQueryExecutor.ts │ ├── query-grammars │ │ ├── IAdvancedQuery.ts │ │ ├── IBasicConditionQuery.ts │ │ ├── IBasicQuery.ts │ │ ├── IConditionQuery.ts │ │ ├── IExecuteQuery.ts │ │ ├── IQuery.ts │ │ └── IRelationQuery.ts │ ├── relations │ │ ├── IBelongsToManyRelationship.ts │ │ ├── IBelongsToRelationship.ts │ │ ├── IHasManyRelationship.ts │ │ ├── IHasOneRelationship.ts │ │ ├── IManyToMany.ts │ │ ├── IMorphManyRelationship.ts │ │ ├── IMorphOneRelationship.ts │ │ ├── IMorphToRelationship.ts │ │ ├── IPivotOptions.ts │ │ ├── IRelationData.ts │ │ ├── IRelationDataBucket.ts │ │ ├── IRelationship.ts │ │ └── IRelationshipFactory.ts │ └── utils │ │ └── IClassSetting.ts ├── drivers │ ├── DriverBase.ts │ ├── ExecutorBase.ts │ ├── QueryLogBase.ts │ ├── Record.ts │ ├── RecordConditionMatcher.ts │ ├── RecordConditionMatcherFactory.ts │ ├── RecordDataReader.ts │ ├── RecordDataSourceBase.ts │ ├── RecordExecutorBase.ts │ ├── RecordManager.ts │ ├── RecordManagerBase.ts │ └── memory │ │ ├── MemoryDataSource.ts │ │ ├── MemoryDriver.ts │ │ ├── MemoryExecutorFactory.ts │ │ ├── MemoryQueryBuilder.ts │ │ ├── MemoryQueryBuilderFactory.ts │ │ ├── MemoryQueryBuilderHandler.ts │ │ ├── MemoryQueryExecutor.ts │ │ ├── MemoryQueryLog.ts │ │ └── MemoryRecordExecutor.ts ├── errors │ ├── NotFoundError.ts │ ├── RelationNotDefinedError.ts │ └── RelationNotFoundInNewInstanceError.ts ├── facades │ ├── container.ts │ └── global │ │ ├── DriverProviderFacade.ts │ │ ├── FactoryFacade.ts │ │ ├── MemoryDataSourceProviderFacade.ts │ │ ├── MomentProviderFacade.ts │ │ └── QueryLogFacade.ts ├── factory │ ├── FactoryBuilder.ts │ └── FactoryManager.ts ├── features │ ├── EventFeature.ts │ ├── FeatureBase.ts │ ├── FillableFeature.ts │ ├── QueryFeature.ts │ ├── RelationFeature.ts │ ├── SerializationFeature.ts │ ├── SettingFeature.ts │ ├── SoftDeletesFeature.ts │ ├── TimestampsFeature.ts │ └── mixin │ │ ├── EventPublicApi.ts │ │ ├── FillablePublicApi.ts │ │ ├── RecordManagerPublicApi.ts │ │ ├── RelationPublicApi.ts │ │ ├── SerializationPublicApi.ts │ │ ├── SoftDeletesPublicApi.ts │ │ └── TimestampsPublicApi.ts ├── index.ts ├── model │ ├── Model.ts │ ├── ModelEvent.ts │ └── ModelProxyHandler.ts ├── providers │ ├── DriverProvider.ts │ ├── MemoryDataSourceProvider.ts │ └── MomentProvider.ts ├── query-builders │ ├── QueryBuilder.ts │ ├── QueryBuilderHandlerBase.ts │ ├── mixin │ │ ├── AdvancedQuery.ts │ │ ├── ConditionQuery.ts │ │ ├── ExecuteQuery.ts │ │ ├── Query.ts │ │ └── RelationQuery.ts │ └── shared │ │ ├── BasicQuery.ts │ │ ├── BasicQueryConverter.ts │ │ ├── ConditionQueryHandler.ts │ │ ├── DefaultConvention.ts │ │ ├── ExecutorUtils.ts │ │ ├── Operator.ts │ │ └── QueryCondition.ts ├── query-log │ └── FlipFlopQueryLog.ts ├── relations │ ├── RelationData.ts │ ├── RelationDataBucket.ts │ ├── RelationDefinitionFinder.ts │ ├── RelationUtilities.ts │ ├── Relationship.ts │ ├── RelationshipFactory.ts │ ├── RelationshipType.ts │ └── relationships │ │ ├── BelongsTo.ts │ │ ├── BelongsToMany.ts │ │ ├── HasMany.ts │ │ ├── HasOne.ts │ │ ├── HasOneOrMany.ts │ │ ├── ManyToMany.ts │ │ ├── MorphMany.ts │ │ ├── MorphOne.ts │ │ ├── MorphTo.ts │ │ ├── executors │ │ ├── HasManyExecutor.ts │ │ ├── HasOneExecutor.ts │ │ ├── HasOneOrManyExecutor.ts │ │ └── MorphOneOrManyExecutor.ts │ │ └── pivot │ │ └── PivotModel.ts └── util │ ├── ClassSetting.ts │ ├── PrototypeManager.ts │ ├── SettingType.ts │ ├── accessors.ts │ ├── factory.ts │ ├── functions.ts │ ├── helpers.ts │ └── isPromise.ts ├── najs-eloquent.code-workspace ├── najs-eloquent.png ├── package-lock.json ├── package.json ├── test ├── _integration │ ├── model │ │ ├── ModelEvent.integration.test.ts │ │ ├── ModelFillable.integration.test.ts │ │ └── ModelSerialization.integration.test.ts │ └── relation │ │ ├── BelongsToMany.softDeletes.test.ts │ │ ├── BelongsToMany.test.ts │ │ ├── BelongsToMany.timestamps.test.ts │ │ ├── HasMany.test.ts │ │ ├── HasOne.test.ts │ │ ├── ManyToMany.PivotDefinition.test.ts │ │ ├── MorphMany.test.ts │ │ └── MorphOne.test.ts ├── _syntax │ └── Factory.test.ts ├── data │ ├── DataBuffer.test.ts │ ├── DataCollector.test.ts │ └── DataConditionMatcher.test.ts ├── drivers │ ├── DriverBase.test.ts │ ├── ExecutorBase.test.ts │ ├── QueryLogBase.test.ts │ ├── Record.test.ts │ ├── RecordConditionMatcher.test.ts │ ├── RecordConditionMatcherFactory.test.ts │ ├── RecordDataReader.test.ts │ ├── RecordDataSourceBase.test.ts │ ├── RecordExecutorBase.test.ts │ ├── RecordManager.test.ts │ ├── RecordManagerBase.test.ts │ └── memory │ │ ├── MemoryDataSource.test.ts │ │ ├── MemoryExecutorFactory.test.ts │ │ ├── MemoryQueryBuilder.test.ts │ │ ├── MemoryQueryBuilderFactory.test.ts │ │ ├── MemoryQueryBuilderHandler.test.ts │ │ ├── MemoryQueryExecutor.test.ts │ │ ├── MemoryQueryLog.test.ts │ │ └── MemoryRecordExecutor.test.ts ├── facades │ ├── container.test.ts │ └── global │ │ ├── EloquentDriverProviderFacade.test.ts │ │ ├── FactoryFacade.test.ts │ │ ├── MemoryDataSourceProviderFacade.test.ts │ │ ├── MomentProviderFacade.test.ts │ │ └── QueryLogFacade.test.ts ├── factory │ ├── FactoryBuilder.test.ts │ └── FactoryManager.test.ts ├── features │ ├── EventFeature.test.ts │ ├── FeatureBase.test.ts │ ├── FillableFeature.test.ts │ ├── QueryFeature.test.ts │ ├── RelationFeature.test.ts │ ├── SerializationFeature.test.ts │ ├── SettingFeature.test.ts │ ├── SoftDeletesFeature.test.ts │ ├── TimestampsFeature.test.ts │ └── mixin │ │ ├── EventPublicApi.test.ts │ │ ├── FillablePublicApi.test.ts │ │ ├── RecordManagerPublicApi.test.ts │ │ ├── RelationPublicApi.test.ts │ │ ├── SerializationPublicApi.test.ts │ │ ├── SoftDeletesPublicApi.test.ts │ │ └── TimestampsPublicApi.test.ts ├── model │ ├── Model.test.ts │ └── ModelProxyHandler.test.ts ├── providers │ ├── DriverProvider.test.ts │ ├── MemoryDataSourceProvider.test.ts │ └── MomentProvider.test.ts ├── query-builders │ ├── QueryBuilder.test.ts │ ├── QueryBuilderHandlerBase.test.ts │ ├── mixin │ │ ├── AdvancedQuery.test.ts │ │ ├── ConditionQuery.test.ts │ │ ├── ExecuteQuery.test.ts │ │ ├── Query.test.ts │ │ └── RelationQuery.test.ts │ └── shared │ │ ├── BasicQuery.test.ts │ │ ├── BasicQueryConverter.test.ts │ │ ├── ConditionQueryHandler.test.ts │ │ ├── DefaultConvention.test.ts │ │ ├── ExecutorUtils.test.ts │ │ └── QueryCondition.test.ts ├── query-log │ └── FlipFlopQueryLog.test.ts ├── relations │ ├── RelationData.test.ts │ ├── RelationDataBucket.test.ts │ ├── RelationDenifitionFinder.test.ts │ ├── RelationUtilities.test.ts │ ├── Relationship.test.ts │ ├── RelationshipFactory.test.ts │ └── relationships │ │ ├── BelongsTo.test.ts │ │ ├── BelongsToMany.test.ts │ │ ├── HasMany.test.ts │ │ ├── HasOne.test.ts │ │ ├── HasOneOrMany.test.ts │ │ ├── ManyToMany.test.ts │ │ ├── MorphMany.test.ts │ │ ├── MorphOne.test.ts │ │ ├── MorphTo.test.ts │ │ ├── executors │ │ ├── HasManyExecutor.test.ts │ │ ├── HasOneExecutor.test.ts │ │ ├── HasOneOrManyExecutor.test.ts │ │ └── MorphOneOrManyExecutor.test.ts │ │ └── pivot │ │ └── PivotModel.test.ts └── util │ ├── ClassSetting.test.ts │ ├── PrototypeManager.test.ts │ ├── SettingType.test.ts │ ├── factory.test.ts │ ├── functions.test.ts │ ├── helpers.test.ts │ └── isPromise.test.ts ├── tsconfig.json ├── tslint.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | integration/dist 61 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | .vscode 61 | lib 62 | test 63 | .travis.yml 64 | tsconfig.json 65 | tslint.json 66 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - CC_TEST_REPORTER_ID=f4c6979c40052fdc70c9ec712fe23f6c0a1fd0c52f2373a5b84334e92e25ddbd 4 | language: node_js 5 | 6 | jobs: 7 | include: 8 | - stage: test 9 | node_js: node 10 | os: linux 11 | before_script: 12 | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter 13 | - chmod +x ./cc-test-reporter 14 | - npm run build || exit 1 15 | - sleep 5 16 | - ./cc-test-reporter before-build 17 | after_success: 18 | - 'cat ./coverage/lcov.info | coveralls' 19 | - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT 20 | 21 | - stage: platform-test 22 | node_js: 'lts/carbon' 23 | os: linux 24 | before_script: sleep 10 25 | 26 | install: 27 | - yarn install 28 | 29 | script: 30 | - npm run test 31 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "eg2.tslint", 4 | "k--kato.intellij-idea-keybindings", 5 | "steoates.autoimport", 6 | "esbenp.prettier-vscode", 7 | "streetsidesoftware.code-spell-checker", 8 | "msjsdiag.debugger-for-chrome", 9 | "PeterJausovec.vscode-docker", 10 | "alefragnani.bookmarks", 11 | "donjayamanne.githistory", 12 | "xabikos.javascriptsnippets", 13 | "Shan.code-settings-sync", 14 | "robertohuertasm.vscode-icons", 15 | "wayou.vscode-todo-highlight" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.tabSize": 2, 3 | "editor.codeLens": false, 4 | "editor.formatOnSave": true, 5 | "editor.rulers": [ 6 | 120 7 | ], 8 | "editor.tabCompletion": true, 9 | "typescript.referencesCodeLens.enabled": true, 10 | "tslint.ignoreDefinitionFiles": false, 11 | "tslint.autoFixOnSave": true, 12 | "tslint.exclude": "**/node_modules/**/*", 13 | "emmet.showExpandedAbbreviation": "never", 14 | "prettier.semi": false, 15 | "prettier.singleQuote": true, 16 | "prettier.tabWidth": 2, 17 | "prettier.printWidth": 120, 18 | "prettier.ignorePath": ".prettierignore", 19 | "terminal.integrated.fontFamily": "Meslo LG M for Powerline", 20 | "terminal.integrated.fontSize": 12, 21 | "cSpell.words": [ 22 | "najs", 23 | "autoload", 24 | "overridable", 25 | "Mailjet", 26 | "Queueable", 27 | "deserialize", 28 | "timestamps", 29 | "mutators" 30 | ] 31 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "label": "Build", 9 | "type": "npm", 10 | "group": "build", 11 | "command": "build" 12 | }, 13 | { 14 | "label": "Test", 15 | "type": "shell", 16 | "group": "test", 17 | "command": "npm run build && npm test" 18 | }, 19 | { 20 | "label": "Coverage", 21 | "type": "shell", 22 | "command": "npm run coverage" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Najs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /dist/lib/contracts/Driver.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | -------------------------------------------------------------------------------- /dist/lib/contracts/DriverProvider.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/contracts/FactoryBuilder.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/contracts/FactoryManager.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | var Model = NajsEloquent.Model.IModel; 6 | -------------------------------------------------------------------------------- /dist/lib/contracts/MemoryDataSource.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace Najs.Contracts.Eloquent { 3 | interface MemoryDataSource extends Najs.Contracts.Autoload, NajsEloquent.Data.IDataBuffer { 4 | /** 5 | * Read data from data source to buffer. 6 | */ 7 | read(): Promise; 8 | /** 9 | * Write buffer to data source. 10 | */ 11 | write(): Promise; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dist/lib/contracts/MemoryDataSource.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/contracts/MemoryDataSourceProvider.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/contracts/MomentProvider.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace Najs.Contracts.Eloquent { 2 | interface MomentProvider extends Najs.Contracts.Autoload { 3 | /** 4 | * Make moment instance 5 | */ 6 | make(...args: any[]): T; 7 | /** 8 | * Determine that the given value is Moment or not 9 | */ 10 | isMoment(value: any): boolean; 11 | /** 12 | * Set now value to the Moment instance 13 | */ 14 | setNow(cb: () => any): this; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dist/lib/contracts/MomentProvider.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/contracts/MomentProvider.js -------------------------------------------------------------------------------- /dist/lib/contracts/QueryLog.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/contracts/QueryLog.js -------------------------------------------------------------------------------- /dist/lib/data/DataBuffer.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare class DataBuffer implements NajsEloquent.Data.IDataBuffer { 4 | protected primaryKeyName: string; 5 | protected reader: NajsEloquent.Data.IDataReader; 6 | protected buffer: Map; 7 | constructor(primaryKeyName: string, reader: NajsEloquent.Data.IDataReader); 8 | getPrimaryKeyName(): string; 9 | getDataReader(): NajsEloquent.Data.IDataReader; 10 | getBuffer(): Map; 11 | add(data: T): this; 12 | remove(data: T): this; 13 | find(cb: (item: T) => boolean): T | undefined; 14 | filter(cb: (item: T) => boolean): T[]; 15 | map(cb: (item: T) => V): V[]; 16 | reduce(cb: ((memo: V, item: T) => V), initialValue: V): V; 17 | keys(): V[]; 18 | [Symbol.iterator](): IterableIterator; 19 | getCollector(): NajsEloquent.Data.IDataCollector; 20 | } 21 | -------------------------------------------------------------------------------- /dist/lib/data/DataConditionMatcher.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare class DataConditionMatcher implements NajsEloquent.QueryBuilder.IConditionMatcher { 4 | protected field: string; 5 | protected operator: string; 6 | protected originalValue: any; 7 | protected value: any; 8 | protected reader: NajsEloquent.Data.IDataReader; 9 | constructor(field: string, operator: string, value: any, reader: NajsEloquent.Data.IDataReader); 10 | isEqual(record: T): boolean; 11 | isLessThan(record: T): boolean; 12 | isLessThanOrEqual(record: T): boolean; 13 | isGreaterThan(record: T): boolean; 14 | isGreaterThanOrEqual(record: T): boolean; 15 | isInArray(record: T): boolean; 16 | isMatch(record: T): boolean; 17 | } 18 | -------------------------------------------------------------------------------- /dist/lib/definitions/data/IDataBuffer.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/data/IDataCollector.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/data/IDataReader.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Data { 2 | interface IDataReader { 3 | /** 4 | * Get an attribute of data. 5 | * 6 | * @param {T} data 7 | * @param {string} field 8 | */ 9 | getAttribute(data: T, field: string): R; 10 | /** 11 | * Pick some fields in data. 12 | * 13 | * @param {object} data 14 | * @param {string[]} fields 15 | */ 16 | pick(data: T, fields: string[]): T; 17 | /** 18 | * Convert give value to comparable value if needed, typically convert value like ObjectID to string. 19 | * 20 | * @param {mixed} value 21 | */ 22 | toComparable(value: any): R; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dist/lib/definitions/data/IDataReader.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/data/IDataReader.js -------------------------------------------------------------------------------- /dist/lib/definitions/driver/IExecutor.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Driver { 2 | interface IExecutor { 3 | /** 4 | * Set execute mode, can set to "disabled" then nothing will executed in db. 5 | * 6 | * @param {string} mode 7 | */ 8 | setExecuteMode(mode: 'default' | 'disabled'): this; 9 | /** 10 | * Determine that should execute a query/command or not. 11 | */ 12 | shouldExecute(): boolean; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /dist/lib/definitions/driver/IExecutor.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/driver/IExecutor.js -------------------------------------------------------------------------------- /dist/lib/definitions/driver/IExecutorFactory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | declare namespace NajsEloquent.Driver { 4 | interface IExecutorFactory { 5 | makeRecordExecutor(model: Model.ModelInternal, record: any): Feature.IRecordExecutor; 6 | makeQueryExecutor(handler: QueryBuilder.IQueryBuilderHandler): QueryBuilder.IQueryExecutor; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dist/lib/definitions/driver/IExecutorFactory.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/factory/IFactoryDefinition.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Factory { 3 | interface IFactoryDefinition { 4 | (faker: Chance.Chance, attributes?: object): object; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /dist/lib/definitions/factory/IFactoryDefinition.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IEventFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Feature { 3 | interface IFeature extends Najs.Contracts.Autoload { 4 | /** 5 | * Attach the public api to prototype of model, it also applies the shared properties to all model instances. 6 | * 7 | * @param {object} prototype 8 | * @param {object[]} bases 9 | * @param {Driver} driver 10 | */ 11 | attachPublicApi(prototype: object, bases: object[], driver: Najs.Contracts.Eloquent.Driver): void; 12 | /** 13 | * Get the feature name. 14 | */ 15 | getFeatureName(): string; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IFillableFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IQueryFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | declare namespace NajsEloquent.Feature { 4 | interface IQueryFeature extends IFeature { 5 | /** 6 | * Create new query builder for model. 7 | */ 8 | newQuery(model: M): NajsEloquent.QueryBuilder.IQueryBuilder; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IQueryFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IRecordExecutor.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | declare namespace NajsEloquent.Feature { 4 | interface IRecordExecutor extends Driver.IExecutor { 5 | /** 6 | * Execute create for record and model. 7 | */ 8 | create(): Promise; 9 | /** 10 | * Execute update for record and model. 11 | */ 12 | update(): Promise; 13 | /** 14 | * Execute hard delete for record and model. 15 | */ 16 | hardDelete(): Promise; 17 | /** 18 | * Execute soft delete for record and model. 19 | */ 20 | softDelete(): Promise; 21 | /** 22 | * Execute restore from soft delete for record and model. 23 | */ 24 | restore(): Promise; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IRecordExecutor.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IRecordManager.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/IRelationFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/ISerializationFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/ISettingFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/ISoftDeletesFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/ITimestampsFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | declare namespace NajsEloquent.Feature { 4 | interface ITimestampsSetting { 5 | createdAt: string; 6 | updatedAt: string; 7 | } 8 | interface ITimestampsFeature extends IFeature { 9 | /** 10 | * Determine the model is using timestamps or not. 11 | */ 12 | hasTimestamps(model: Model.IModel): boolean; 13 | /** 14 | * Get timestamps setting. 15 | * 16 | * Note: It's returns default timestamps even the model is not using timestamps. 17 | */ 18 | getTimestampsSetting(model: Model.IModel): ITimestampsSetting; 19 | /** 20 | * Update the model's update timestamp. 21 | */ 22 | touch(model: Model.IModel): void; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dist/lib/definitions/features/ITimestampsFeature.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModel.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | /// 12 | var NajsEloquent; 13 | (function (NajsEloquent) { 14 | var Model; 15 | (function (Model) { 16 | })(Model = NajsEloquent.Model || (NajsEloquent.Model = {})); 17 | })(NajsEloquent || (NajsEloquent = {})); 18 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelEvent.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Model { 2 | interface IModelEvent extends Najs.Contracts.Event.AsyncEventEmitter { 3 | /** 4 | * Trigger the event with both global and local EventEmitter. 5 | * 6 | * Listener in local EventEmitter triggered with the same args, in Global EventEmitter automatically add the model 7 | * instance as the first argument. For example: 8 | * 9 | * model.fire('test', [1, 2]) 10 | * 11 | * then: 12 | * 13 | * local_listener(data) // data = [1, 2] 14 | * global_listener(model, data) // model triggered, data = [1, 2] 15 | * 16 | * @param {string} eventName event's name 17 | * @param {mixed} args arguments 18 | */ 19 | fire(eventName: string, args?: any): Promise; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelEvent.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelFillable.js: -------------------------------------------------------------------------------- 1 | var NajsEloquent; 2 | (function (NajsEloquent) { 3 | var Model; 4 | (function (Model) { 5 | })(Model = NajsEloquent.Model || (NajsEloquent.Model = {})); 6 | })(NajsEloquent || (NajsEloquent = {})); 7 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelRecord.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/model/IModelRecord.js -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelRelation.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelSerialization.js: -------------------------------------------------------------------------------- 1 | var NajsEloquent; 2 | (function (NajsEloquent) { 3 | var Model; 4 | (function (Model) { 5 | })(Model = NajsEloquent.Model || (NajsEloquent.Model = {})); 6 | })(NajsEloquent || (NajsEloquent = {})); 7 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelSoftDeletes.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Model { 3 | class IModelSoftDeletes { 4 | /** 5 | * Soft deletes setting 6 | */ 7 | protected softDeletes?: Feature.ISoftDeletesSetting | boolean; 8 | } 9 | interface IModelSoftDeletes { 10 | /** 11 | * Determine model is soft-deleted or not. 12 | */ 13 | trashed(): boolean; 14 | /** 15 | * Delete the model even soft delete is enabled. 16 | */ 17 | forceDelete(): Promise; 18 | /** 19 | * Restore the model, only applied for model which has soft delete setting is enabled. 20 | */ 21 | restore(): Promise; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelSoftDeletes.js: -------------------------------------------------------------------------------- 1 | /// 2 | var NajsEloquent; 3 | (function (NajsEloquent) { 4 | var Model; 5 | (function (Model) { 6 | })(Model = NajsEloquent.Model || (NajsEloquent.Model = {})); 7 | })(NajsEloquent || (NajsEloquent = {})); 8 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelTimestamps.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Model { 3 | class IModelTimestamps { 4 | /** 5 | * Timestamps setting. 6 | */ 7 | protected timestamps?: Feature.ITimestampsSetting | boolean; 8 | } 9 | interface IModelTimestamps { 10 | /** 11 | * Update the model's update timestamp. 12 | */ 13 | touch(): this; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/definitions/model/IModelTimestamps.js: -------------------------------------------------------------------------------- 1 | /// 2 | var NajsEloquent; 3 | (function (NajsEloquent) { 4 | var Model; 5 | (function (Model) { 6 | })(Model = NajsEloquent.Model || (NajsEloquent.Model = {})); 7 | })(NajsEloquent || (NajsEloquent = {})); 8 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IConditionMatcher.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.QueryBuilder { 2 | type GroupQueryConditionData = { 3 | bool: 'and' | 'or'; 4 | queries: Array; 5 | }; 6 | type SingleQueryConditionData = { 7 | bool: 'and' | 'or'; 8 | field: string; 9 | operator: QueryGrammar.Operator; 10 | value: any; 11 | }; 12 | interface IConditionMatcher { 13 | isMatch(record: T): boolean; 14 | } 15 | interface IConditionMatcherFactory { 16 | make(data: SingleQueryConditionData): IConditionMatcher; 17 | transform(matcher: IConditionMatcher): any; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IConditionMatcher.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/query-builders/IConditionMatcher.js -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IConvention.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.QueryBuilder { 2 | interface IConvention { 3 | /** 4 | * Format the given name 5 | * 6 | * @param {string} name 7 | */ 8 | formatFieldName(name: string): string; 9 | /** 10 | * Get null value for given name 11 | * 12 | * @param {string} name 13 | */ 14 | getNullValueFor(name: string): any; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IConvention.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/query-builders/IConvention.js -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryBuilder.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | declare namespace NajsEloquent.QueryBuilder { 7 | class IQueryBuilder { 8 | protected handler: Handler; 9 | } 10 | interface IQueryBuilder extends QueryGrammar.IQuery, QueryGrammar.IConditionQuery, QueryGrammar.IExecuteQuery, QueryGrammar.IAdvancedQuery, QueryGrammar.IRelationQuery { 11 | } 12 | type QueryBuilderInternal = IQueryBuilder & { 13 | handler: NajsEloquent.QueryBuilder.IQueryBuilderHandler; 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryBuilder.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | var NajsEloquent; 7 | (function (NajsEloquent) { 8 | var QueryBuilder; 9 | (function (QueryBuilder) { 10 | // export type OmittedResult = Pick) | (keyof K)>> 11 | // export type OmittedQueryBuilderResult = Pick>> 12 | })(QueryBuilder = NajsEloquent.QueryBuilder || (NajsEloquent.QueryBuilder = {})); 13 | })(NajsEloquent || (NajsEloquent = {})); 14 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryBuilderFactory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | declare namespace NajsEloquent.QueryBuilder { 5 | interface IQueryBuilderFactory extends Najs.Contracts.Autoload { 6 | /** 7 | * Make new query builder instance from a model. 8 | * 9 | * @param {Model} model 10 | */ 11 | make(model: Model.IModel): IQueryBuilder; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryBuilderFactory.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryBuilderHandler.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-builders/IQueryExecutor.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IAdvancedQuery.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IBasicConditionQuery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/query-grammars/IBasicConditionQuery.js -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IBasicQuery.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.QueryGrammar { 2 | interface IBasicQuery { 3 | /** 4 | * Set the columns or fields to be selected. 5 | * 6 | * @param {string|string[]} fields 7 | */ 8 | select(...fields: Array): this; 9 | /** 10 | * Set the "limit" value of the query. 11 | * @param {number} records 12 | */ 13 | limit(record: number): this; 14 | /** 15 | * Add an "order by" clause to the query. 16 | * 17 | * @param {string} field 18 | */ 19 | orderBy(field: string): this; 20 | /** 21 | * Add an "order by" clause to the query. 22 | * 23 | * @param {string} field 24 | * @param {string} direction 25 | */ 26 | orderBy(field: string, direction: 'asc' | 'desc'): this; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IBasicQuery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/query-grammars/IBasicQuery.js -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IConditionQuery.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IExecuteQuery.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.QueryGrammar { 3 | interface IExecuteQuery { 4 | /** 5 | * Execute query and returns count of records. 6 | */ 7 | count(): Promise; 8 | /** 9 | * Update records which match the query with data. 10 | * 11 | * @param {Object} data 12 | */ 13 | update(data: Object): Promise; 14 | /** 15 | * Delete all records which match the query. 16 | */ 17 | delete(): Promise; 18 | /** 19 | * Restore all records which match the query. 20 | */ 21 | restore(): Promise; 22 | /** 23 | * Execute query and returns raw result. 24 | */ 25 | execute(): Promise; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IExecuteQuery.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IQuery.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IRelationQuery.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.QueryGrammar { 2 | interface IRelationQuery { 3 | /** 4 | * Load given relations name when the query get executed. 5 | * 6 | * @param {string|string[]} relations 7 | */ 8 | with(...relations: Array): this; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dist/lib/definitions/query-grammars/IRelationQuery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/query-grammars/IRelationQuery.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IBelongsToManyRelationship.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IBelongsToRelationship.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Relation { 2 | interface IBelongsToRelationship extends IRelationship { 3 | dissociate(): void; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IBelongsToRelationship.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/relations/IBelongsToRelationship.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IHasManyRelationship.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Relation { 3 | interface IHasManyRelationship extends IRelationship> { 4 | associate(...models: Array>): this; 5 | dissociate(...models: Array>): this; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IHasManyRelationship.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IHasOneRelationship.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Relation { 2 | interface IHasOneRelationship extends IRelationship { 3 | associate(model: T): void; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IHasOneRelationship.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/relations/IHasOneRelationship.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IManyToMany.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphManyRelationship.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Relation { 3 | interface IMorphManyRelationship extends IRelationship> { 4 | associate(...models: Array>): this; 5 | dissociate(...models: Array>): this; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphManyRelationship.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphOneRelationship.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Relation { 2 | interface IMorphOneRelationship extends IRelationship { 3 | associate(model: T): void; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphOneRelationship.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/relations/IMorphOneRelationship.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphToRelationship.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Relation { 2 | interface IMorphToRelationship extends IRelationship { 3 | } 4 | } 5 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IMorphToRelationship.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/relations/IMorphToRelationship.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IPivotOptions.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Relation { 2 | type PivotForeignKey = string; 3 | interface IPivotOptions { 4 | foreignKeys: [PivotForeignKey, PivotForeignKey]; 5 | name?: string; 6 | fields?: Array; 7 | timestamps?: Feature.ITimestampsSetting; 8 | softDeletes?: Feature.ISoftDeletesSetting; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IPivotOptions.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/relations/IPivotOptions.js -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IRelationData.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace NajsEloquent.Relation { 3 | interface IRelationData { 4 | getFactory(): IRelationshipFactory; 5 | isLoaded(): boolean; 6 | hasData(): boolean; 7 | getData(): T | undefined | null; 8 | setData(data: T | undefined | null): T | undefined | null; 9 | getLoadType(): 'unknown' | 'lazy' | 'eager'; 10 | setLoadType(type: 'lazy' | 'eager'): this; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IRelationData.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IRelationDataBucket.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IRelationship.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /dist/lib/definitions/relations/IRelationshipFactory.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | var IModel = NajsEloquent.Model.IModel; 10 | -------------------------------------------------------------------------------- /dist/lib/definitions/utils/IClassSetting.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace NajsEloquent.Util { 2 | interface ISettingReader { 3 | (staticValue?: T, sampleValue?: T, instanceValue?: T): T; 4 | } 5 | interface IClassSetting { 6 | /** 7 | * Read property setting via a setting reader. 8 | * 9 | * @param {string} property 10 | * @param {Function} reader 11 | */ 12 | read(property: string, reader: ISettingReader): T; 13 | /** 14 | * Get the "sample" instance. 15 | */ 16 | getSample(): T; 17 | /** 18 | * Get definition of the class. 19 | */ 20 | getDefinition(): Function; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /dist/lib/definitions/utils/IClassSetting.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/dist/lib/definitions/utils/IClassSetting.js -------------------------------------------------------------------------------- /dist/lib/drivers/ExecutorBase.d.ts: -------------------------------------------------------------------------------- 1 | export declare class ExecutorBase { 2 | private executeMode; 3 | setExecuteMode(mode: 'default' | 'disabled'): this; 4 | shouldExecute(): boolean; 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/drivers/ExecutorBase.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class ExecutorBase { 4 | constructor() { 5 | this.executeMode = 'default'; 6 | } 7 | setExecuteMode(mode) { 8 | this.executeMode = mode; 9 | return this; 10 | } 11 | shouldExecute() { 12 | return this.executeMode !== 'disabled'; 13 | } 14 | } 15 | exports.ExecutorBase = ExecutorBase; 16 | -------------------------------------------------------------------------------- /dist/lib/drivers/QueryLogBase.d.ts: -------------------------------------------------------------------------------- 1 | export interface IQueryLogData { 2 | raw: string; 3 | result?: any; 4 | name?: string; 5 | action?: string; 6 | queryBuilderData: object; 7 | } 8 | export declare abstract class QueryLogBase { 9 | protected data: T; 10 | constructor(); 11 | abstract getDefaultData(): T; 12 | getEmptyData(): IQueryLogData; 13 | queryBuilderData(key: string, value: any): this; 14 | name(name: string): this; 15 | action(action: string): this; 16 | raw(raw: any): this; 17 | raw(...raw: any[]): this; 18 | end(result: any): any; 19 | } 20 | -------------------------------------------------------------------------------- /dist/lib/drivers/Record.d.ts: -------------------------------------------------------------------------------- 1 | export declare class Record { 2 | protected data: object; 3 | protected modified: string[]; 4 | constructor(data?: object | Record); 5 | getAttribute(path: string): T; 6 | setAttribute(path: string, value: T): boolean; 7 | clearModified(): this; 8 | getModified(): string[]; 9 | markModified(name: string): void; 10 | toObject(): object; 11 | } 12 | -------------------------------------------------------------------------------- /dist/lib/drivers/Record.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const lodash_1 = require("lodash"); 4 | class Record { 5 | constructor(data) { 6 | if (data instanceof Record) { 7 | this.data = data.data; 8 | } 9 | else { 10 | this.data = data || {}; 11 | } 12 | this.modified = []; 13 | } 14 | getAttribute(path) { 15 | return lodash_1.get(this.data, path); 16 | } 17 | setAttribute(path, value) { 18 | const originalValue = lodash_1.get(this.data, path); 19 | if (!lodash_1.isEqual(originalValue, value)) { 20 | lodash_1.set(this.data, path, value); 21 | this.markModified(path); 22 | } 23 | return true; 24 | } 25 | clearModified() { 26 | this.modified = []; 27 | return this; 28 | } 29 | getModified() { 30 | return this.modified; 31 | } 32 | markModified(name) { 33 | if (this.modified.indexOf(name) === -1) { 34 | this.modified.push(name); 35 | } 36 | } 37 | toObject() { 38 | return this.data; 39 | } 40 | } 41 | exports.Record = Record; 42 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordConditionMatcher.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import IConditionMatcher = NajsEloquent.QueryBuilder.IConditionMatcher; 3 | import { Record } from './Record'; 4 | import { DataConditionMatcher } from '../data/DataConditionMatcher'; 5 | export declare class RecordConditionMatcher extends DataConditionMatcher implements IConditionMatcher { 6 | constructor(field: string, operator: string, value: any); 7 | toJSON(): object; 8 | } 9 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordConditionMatcher.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const DataConditionMatcher_1 = require("../data/DataConditionMatcher"); 5 | const RecordDataReader_1 = require("./RecordDataReader"); 6 | class RecordConditionMatcher extends DataConditionMatcher_1.DataConditionMatcher { 7 | constructor(field, operator, value) { 8 | super(field, operator, value, RecordDataReader_1.RecordDataReader); 9 | } 10 | toJSON() { 11 | return { 12 | field: this.field, 13 | operator: this.operator, 14 | value: this.value 15 | }; 16 | } 17 | } 18 | exports.RecordConditionMatcher = RecordConditionMatcher; 19 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordConditionMatcherFactory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import IConditionMatcherFactory = NajsEloquent.QueryBuilder.IConditionMatcherFactory; 3 | import SingleQueryConditionData = NajsEloquent.QueryBuilder.SingleQueryConditionData; 4 | import { RecordConditionMatcher } from './RecordConditionMatcher'; 5 | export declare class RecordConditionMatcherFactory implements IConditionMatcherFactory { 6 | static className: string; 7 | getClassName(): string; 8 | make(data: SingleQueryConditionData): RecordConditionMatcher; 9 | transform(matcher: RecordConditionMatcher): RecordConditionMatcher; 10 | } 11 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordConditionMatcherFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const najs_binding_1 = require("najs-binding"); 5 | const RecordConditionMatcher_1 = require("./RecordConditionMatcher"); 6 | const constants_1 = require("../constants"); 7 | class RecordConditionMatcherFactory { 8 | getClassName() { 9 | return constants_1.NajsEloquent.Driver.Memory.RecordConditionMatcherFactory; 10 | } 11 | make(data) { 12 | return new RecordConditionMatcher_1.RecordConditionMatcher(data.field, data.operator, data.value); 13 | } 14 | transform(matcher) { 15 | return matcher; 16 | } 17 | } 18 | RecordConditionMatcherFactory.className = constants_1.NajsEloquent.Driver.Memory.RecordConditionMatcherFactory; 19 | exports.RecordConditionMatcherFactory = RecordConditionMatcherFactory; 20 | najs_binding_1.register(RecordConditionMatcherFactory, constants_1.NajsEloquent.Driver.Memory.RecordConditionMatcherFactory, true, true); 21 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordDataReader.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Record } from './Record'; 3 | export declare const RecordDataReader: NajsEloquent.Data.IDataReader; 4 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordDataReader.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const lodash_1 = require("lodash"); 5 | const Record_1 = require("./Record"); 6 | const helpers_1 = require("../util/helpers"); 7 | exports.RecordDataReader = { 8 | getAttribute(data, field) { 9 | return this.toComparable(data.getAttribute(field)); 10 | }, 11 | pick(record, selectedFields) { 12 | const data = record.toObject(); 13 | return new Record_1.Record(lodash_1.pick(data, selectedFields)); 14 | }, 15 | toComparable(value) { 16 | return helpers_1.isObjectId(value) ? value.toHexString() : value; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordDataSourceBase.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { Record } from './Record'; 4 | import { DataBuffer } from '../data/DataBuffer'; 5 | export declare abstract class RecordDataSourceBase extends DataBuffer implements Najs.Contracts.Eloquent.MemoryDataSource { 6 | protected modelName: string; 7 | constructor(model: NajsEloquent.Model.IModel); 8 | getModelName(): string; 9 | abstract getClassName(): string; 10 | abstract createPrimaryKeyIfNeeded(data: Record): string; 11 | abstract read(): Promise; 12 | abstract write(): Promise; 13 | add(data: Record): this; 14 | remove(data: Record): this; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/drivers/RecordDataSourceBase.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | /// 4 | Object.defineProperty(exports, "__esModule", { value: true }); 5 | const RecordDataReader_1 = require("./RecordDataReader"); 6 | const DataBuffer_1 = require("../data/DataBuffer"); 7 | class RecordDataSourceBase extends DataBuffer_1.DataBuffer { 8 | constructor(model) { 9 | super(model.getPrimaryKeyName(), RecordDataReader_1.RecordDataReader); 10 | this.modelName = model.getModelName(); 11 | } 12 | getModelName() { 13 | return this.modelName; 14 | } 15 | add(data) { 16 | this.createPrimaryKeyIfNeeded(data); 17 | return super.add(data); 18 | } 19 | remove(data) { 20 | this.createPrimaryKeyIfNeeded(data); 21 | return super.remove(data); 22 | } 23 | } 24 | exports.RecordDataSourceBase = RecordDataSourceBase; 25 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryDataSource.d.ts: -------------------------------------------------------------------------------- 1 | import { Record } from '../Record'; 2 | import { RecordDataSourceBase } from '../RecordDataSourceBase'; 3 | export declare class MemoryDataSource extends RecordDataSourceBase { 4 | static className: string; 5 | getClassName(): string; 6 | createPrimaryKeyIfNeeded(data: Record): string; 7 | read(): Promise; 8 | write(): Promise; 9 | } 10 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryDataSource.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const najs_binding_1 = require("najs-binding"); 4 | const bson_1 = require("bson"); 5 | const constants_1 = require("../../constants"); 6 | const RecordDataSourceBase_1 = require("../RecordDataSourceBase"); 7 | class MemoryDataSource extends RecordDataSourceBase_1.RecordDataSourceBase { 8 | getClassName() { 9 | return constants_1.NajsEloquent.Driver.Memory.MemoryDataSource; 10 | } 11 | createPrimaryKeyIfNeeded(data) { 12 | const primaryKey = data.getAttribute(this.primaryKeyName); 13 | if (primaryKey) { 14 | return primaryKey; 15 | } 16 | const newId = new bson_1.ObjectId().toHexString(); 17 | data.setAttribute(this.primaryKeyName, newId); 18 | return newId; 19 | } 20 | async read() { 21 | return true; 22 | } 23 | async write() { 24 | return true; 25 | } 26 | } 27 | MemoryDataSource.className = constants_1.NajsEloquent.Driver.Memory.MemoryDataSource; 28 | exports.MemoryDataSource = MemoryDataSource; 29 | najs_binding_1.register(MemoryDataSource, constants_1.NajsEloquent.Driver.Memory.MemoryDataSource); 30 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryDriver.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import '../RecordManager'; 5 | import { DriverBase } from '../DriverBase'; 6 | import { Record } from '../Record'; 7 | import { MemoryQueryBuilderFactory } from './MemoryQueryBuilderFactory'; 8 | export declare class MemoryDriver extends DriverBase { 9 | protected recordManager: NajsEloquent.Feature.IRecordManager; 10 | static Name: string; 11 | constructor(); 12 | getClassName(): string; 13 | getRecordManager(): NajsEloquent.Feature.IRecordManager; 14 | makeQueryBuilderFactory(): MemoryQueryBuilderFactory; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryExecutorFactory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import IModel = NajsEloquent.Model.IModel; 5 | import { Record } from '../Record'; 6 | import { MemoryRecordExecutor } from './MemoryRecordExecutor'; 7 | import { MemoryQueryBuilderHandler } from './MemoryQueryBuilderHandler'; 8 | import { MemoryQueryLog } from './MemoryQueryLog'; 9 | export declare class MemoryExecutorFactory implements NajsEloquent.Driver.IExecutorFactory { 10 | static className: string; 11 | makeRecordExecutor(model: IModel, record: T): MemoryRecordExecutor; 12 | makeQueryExecutor(handler: MemoryQueryBuilderHandler): any; 13 | getClassName(): string; 14 | getDataSource(model: IModel): Najs.Contracts.Eloquent.MemoryDataSource; 15 | makeLogger(): MemoryQueryLog; 16 | } 17 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryBuilder.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import IModel = NajsEloquent.Model.IModel; 3 | import { QueryBuilder } from '../../query-builders/QueryBuilder'; 4 | import { MemoryQueryBuilderHandler } from './MemoryQueryBuilderHandler'; 5 | export declare class MemoryQueryBuilder extends QueryBuilder { 6 | } 7 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const QueryBuilder_1 = require("../../query-builders/QueryBuilder"); 5 | class MemoryQueryBuilder extends QueryBuilder_1.QueryBuilder { 6 | } 7 | exports.MemoryQueryBuilder = MemoryQueryBuilder; 8 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryBuilderFactory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import { MemoryQueryBuilder } from './MemoryQueryBuilder'; 5 | export declare class MemoryQueryBuilderFactory implements NajsEloquent.QueryBuilder.IQueryBuilderFactory { 6 | static className: string; 7 | getClassName(): string; 8 | make(model: NajsEloquent.Model.IModel): MemoryQueryBuilder; 9 | } 10 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryBuilderFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | /// 4 | /// 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const najs_binding_1 = require("najs-binding"); 7 | const constants_1 = require("../../constants"); 8 | const MemoryQueryBuilder_1 = require("./MemoryQueryBuilder"); 9 | const MemoryQueryBuilderHandler_1 = require("./MemoryQueryBuilderHandler"); 10 | class MemoryQueryBuilderFactory { 11 | getClassName() { 12 | return constants_1.NajsEloquent.Driver.Memory.MemoryQueryBuilderFactory; 13 | } 14 | make(model) { 15 | return new MemoryQueryBuilder_1.MemoryQueryBuilder(new MemoryQueryBuilderHandler_1.MemoryQueryBuilderHandler(model)); 16 | } 17 | } 18 | MemoryQueryBuilderFactory.className = constants_1.NajsEloquent.Driver.Memory.MemoryQueryBuilderFactory; 19 | exports.MemoryQueryBuilderFactory = MemoryQueryBuilderFactory; 20 | najs_binding_1.register(MemoryQueryBuilderFactory, constants_1.NajsEloquent.Driver.Memory.MemoryQueryBuilderFactory, true, true); 21 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryBuilderHandler.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | import IModel = NajsEloquent.Model.IModel; 7 | import IConvention = NajsEloquent.QueryBuilder.IConvention; 8 | import IConditionQuery = NajsEloquent.QueryGrammar.IConditionQuery; 9 | import { QueryBuilderHandlerBase } from '../../query-builders/QueryBuilderHandlerBase'; 10 | import { BasicQuery } from '../../query-builders/shared/BasicQuery'; 11 | import { ConditionQueryHandler } from '../../query-builders/shared/ConditionQueryHandler'; 12 | export declare class MemoryQueryBuilderHandler extends QueryBuilderHandlerBase { 13 | protected basicQuery: BasicQuery; 14 | protected conditionQuery: ConditionQueryHandler; 15 | protected convention: IConvention; 16 | constructor(model: IModel); 17 | getBasicQuery(): BasicQuery; 18 | getConditionQuery(): IConditionQuery; 19 | getQueryConvention(): IConvention; 20 | } 21 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryLog.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import MemoryDataSource = Najs.Contracts.Eloquent.MemoryDataSource; 3 | import { Record } from '../Record'; 4 | import { QueryLogBase, IQueryLogData } from '../QueryLogBase'; 5 | export interface IMemoryLogData extends IQueryLogData { 6 | dataSource?: string; 7 | records?: IUpdateRecordInfo[]; 8 | } 9 | export interface IUpdateRecordInfo { 10 | origin: object; 11 | modified: boolean; 12 | updated: object; 13 | } 14 | export declare class MemoryQueryLog extends QueryLogBase { 15 | getDefaultData(): IMemoryLogData; 16 | dataSource(ds: MemoryDataSource): this; 17 | updateRecordInfo(info: IUpdateRecordInfo): this; 18 | } 19 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryQueryLog.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const QueryLogBase_1 = require("../QueryLogBase"); 4 | class MemoryQueryLog extends QueryLogBase_1.QueryLogBase { 5 | getDefaultData() { 6 | return this.getEmptyData(); 7 | } 8 | dataSource(ds) { 9 | this.data.dataSource = ds.getClassName(); 10 | return this; 11 | } 12 | updateRecordInfo(info) { 13 | if (typeof this.data.records === 'undefined') { 14 | this.data.records = []; 15 | } 16 | this.data.records.push(info); 17 | return this; 18 | } 19 | } 20 | exports.MemoryQueryLog = MemoryQueryLog; 21 | -------------------------------------------------------------------------------- /dist/lib/drivers/memory/MemoryRecordExecutor.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import Model = NajsEloquent.Model.IModel; 4 | import MemoryDataSource = Najs.Contracts.Eloquent.MemoryDataSource; 5 | import { RecordExecutorBase } from '../RecordExecutorBase'; 6 | import { MemoryQueryLog } from './MemoryQueryLog'; 7 | import { Record } from '../Record'; 8 | export declare class MemoryRecordExecutor extends RecordExecutorBase { 9 | protected dataSource: MemoryDataSource; 10 | protected logger: MemoryQueryLog; 11 | constructor(model: Model, record: Record, dataSource: MemoryDataSource, logger: MemoryQueryLog); 12 | saveRecord(action: string): Promise; 13 | createRecord(action: string): Promise; 14 | updateRecord(action: string): Promise; 15 | hardDeleteRecord(): Promise; 16 | logRaw(func: string, data: any): MemoryQueryLog; 17 | } 18 | -------------------------------------------------------------------------------- /dist/lib/errors/NotFoundError.d.ts: -------------------------------------------------------------------------------- 1 | export declare class NotFoundError extends Error { 2 | static className: string; 3 | model: string; 4 | constructor(model: string); 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/errors/NotFoundError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const MESSAGE = ':model is not found.'; 4 | class NotFoundError extends Error { 5 | constructor(model) { 6 | super(MESSAGE.replace(':model', model)); 7 | Error.captureStackTrace(this, NotFoundError); 8 | this.name = NotFoundError.className; 9 | this.model = model; 10 | } 11 | } 12 | NotFoundError.className = 'NotFoundError'; 13 | exports.NotFoundError = NotFoundError; 14 | -------------------------------------------------------------------------------- /dist/lib/errors/RelationNotDefinedError.d.ts: -------------------------------------------------------------------------------- 1 | export declare class RelationNotDefinedError extends Error { 2 | static className: string; 3 | relationName: string; 4 | model: string; 5 | constructor(name: string, model: string); 6 | } 7 | -------------------------------------------------------------------------------- /dist/lib/errors/RelationNotDefinedError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const MESSAGE = 'Relation :name is not defined in model :model.'; 4 | class RelationNotDefinedError extends Error { 5 | constructor(name, model) { 6 | super(MESSAGE.replace(':name', name).replace(':model', model)); 7 | Error.captureStackTrace(this, RelationNotDefinedError); 8 | this.name = RelationNotDefinedError.className; 9 | this.relationName = name; 10 | this.model = model; 11 | } 12 | } 13 | RelationNotDefinedError.className = 'NotFoundError'; 14 | exports.RelationNotDefinedError = RelationNotDefinedError; 15 | -------------------------------------------------------------------------------- /dist/lib/errors/RelationNotFoundInNewInstanceError.d.ts: -------------------------------------------------------------------------------- 1 | export declare class RelationNotFoundInNewInstanceError extends Error { 2 | static className: string; 3 | relationName: string; 4 | model: string; 5 | constructor(name: string, model: string); 6 | } 7 | -------------------------------------------------------------------------------- /dist/lib/errors/RelationNotFoundInNewInstanceError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const MESSAGE = 'Cannot load relation :name in a new instance of :model.'; 4 | class RelationNotFoundInNewInstanceError extends Error { 5 | constructor(name, model) { 6 | super(MESSAGE.replace(':name', name).replace(':model', model)); 7 | Error.captureStackTrace(this, RelationNotFoundInNewInstanceError); 8 | this.name = RelationNotFoundInNewInstanceError.className; 9 | this.relationName = name; 10 | this.model = model; 11 | } 12 | } 13 | RelationNotFoundInNewInstanceError.className = 'RelationNotFoundInNewInstanceError'; 14 | exports.RelationNotFoundInNewInstanceError = RelationNotFoundInNewInstanceError; 15 | -------------------------------------------------------------------------------- /dist/lib/facades/container.d.ts: -------------------------------------------------------------------------------- 1 | import { IFacadeContainer } from 'najs-facade'; 2 | export declare const container: IFacadeContainer; 3 | -------------------------------------------------------------------------------- /dist/lib/facades/container.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const najs_facade_1 = require("najs-facade"); 4 | class NajsEloquentBag extends najs_facade_1.FacadeContainer { 5 | } 6 | exports.container = new NajsEloquentBag(); 7 | global['NajsEloquent'] = exports.container; 8 | -------------------------------------------------------------------------------- /dist/lib/facades/global/DriverProviderFacade.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import '../../providers/DriverProvider'; 3 | import { IFacade, IFacadeBase } from 'najs-facade'; 4 | export declare const DriverProviderFacade: Najs.Contracts.Eloquent.DriverProvider & IFacade; 5 | export declare const DriverProvider: Najs.Contracts.Eloquent.DriverProvider & IFacadeBase; 6 | -------------------------------------------------------------------------------- /dist/lib/facades/global/DriverProviderFacade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | require("../../providers/DriverProvider"); 5 | const najs_binding_1 = require("najs-binding"); 6 | const najs_facade_1 = require("najs-facade"); 7 | const container_1 = require("../container"); 8 | const constants_1 = require("../../constants"); 9 | const facade = najs_facade_1.Facade.create(container_1.container, 'DriverProvider', function () { 10 | return najs_binding_1.make(constants_1.NajsEloquent.Provider.DriverProvider); 11 | }); 12 | exports.DriverProviderFacade = facade; 13 | exports.DriverProvider = facade; 14 | -------------------------------------------------------------------------------- /dist/lib/facades/global/FactoryFacade.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import '../../factory/FactoryManager'; 3 | import { IFacade, IFacadeBase } from 'najs-facade'; 4 | export declare const FactoryFacade: Najs.Contracts.Eloquent.FactoryManager & IFacade; 5 | export declare const Factory: Najs.Contracts.Eloquent.FactoryManager & IFacadeBase; 6 | export declare const factory: Najs.Contracts.Eloquent.FactoryFunction; 7 | -------------------------------------------------------------------------------- /dist/lib/facades/global/FactoryFacade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | require("../../factory/FactoryManager"); 5 | const najs_binding_1 = require("najs-binding"); 6 | const najs_facade_1 = require("najs-facade"); 7 | const container_1 = require("../container"); 8 | const constants_1 = require("../../constants"); 9 | const facade = najs_facade_1.Facade.create(container_1.container, 'FactoryManager', function () { 10 | return najs_binding_1.make(constants_1.NajsEloquent.Factory.FactoryManager); 11 | }); 12 | exports.FactoryFacade = facade; 13 | exports.Factory = facade; 14 | exports.factory = (function (className, arg1, arg2) { 15 | let name = 'default'; 16 | if (typeof arg1 === 'string') { 17 | name = arg1; 18 | } 19 | let amount = undefined; 20 | if (typeof arg1 === 'number') { 21 | amount = arg1; 22 | } 23 | if (typeof arg2 === 'number') { 24 | amount = arg2; 25 | } 26 | return typeof amount === 'undefined' 27 | ? exports.Factory.of(className, name) 28 | : exports.Factory.of(className, name).times(amount); 29 | }); 30 | -------------------------------------------------------------------------------- /dist/lib/facades/global/MemoryDataSourceProviderFacade.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import '../../providers/MemoryDataSourceProvider'; 3 | import { Record } from '../../drivers/Record'; 4 | import { IFacade, IFacadeBase } from 'najs-facade'; 5 | export declare const MemoryDataSourceProviderFacade: Najs.Contracts.Eloquent.MemoryDataSourceProvider & IFacade; 6 | export declare const MemoryDataSourceProvider: Najs.Contracts.Eloquent.MemoryDataSourceProvider & IFacadeBase; 7 | -------------------------------------------------------------------------------- /dist/lib/facades/global/MemoryDataSourceProviderFacade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | require("../../providers/MemoryDataSourceProvider"); 5 | const najs_binding_1 = require("najs-binding"); 6 | const najs_facade_1 = require("najs-facade"); 7 | const container_1 = require("../container"); 8 | const constants_1 = require("../../constants"); 9 | const facade = najs_facade_1.Facade.create(container_1.container, 'MemoryDataSourceProvider', function () { 10 | return najs_binding_1.make(constants_1.NajsEloquent.Provider.MemoryDataSourceProvider); 11 | }); 12 | exports.MemoryDataSourceProviderFacade = facade; 13 | exports.MemoryDataSourceProvider = facade; 14 | -------------------------------------------------------------------------------- /dist/lib/facades/global/MomentProviderFacade.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import '../../providers/MomentProvider'; 3 | import { IFacade, IFacadeBase } from 'najs-facade'; 4 | import { Moment } from 'moment'; 5 | export declare const MomentProviderFacade: Najs.Contracts.Eloquent.MomentProvider & IFacade; 6 | export declare const MomentProvider: Najs.Contracts.Eloquent.MomentProvider & IFacadeBase; 7 | -------------------------------------------------------------------------------- /dist/lib/facades/global/MomentProviderFacade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | require("../../providers/MomentProvider"); 5 | const najs_binding_1 = require("najs-binding"); 6 | const najs_facade_1 = require("najs-facade"); 7 | const container_1 = require("../container"); 8 | const constants_1 = require("../../constants"); 9 | const facade = najs_facade_1.Facade.create(container_1.container, 'MomentProvider', function () { 10 | return najs_binding_1.make(constants_1.NajsEloquent.Provider.MomentProvider); 11 | }); 12 | exports.MomentProviderFacade = facade; 13 | exports.MomentProvider = facade; 14 | -------------------------------------------------------------------------------- /dist/lib/facades/global/QueryLogFacade.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import '../../query-log/FlipFlopQueryLog'; 3 | import { IFacade, IFacadeBase } from 'najs-facade'; 4 | export declare const QueryLogFacade: Najs.Contracts.Eloquent.QueryLog & IFacade; 5 | export declare const QueryLog: Najs.Contracts.Eloquent.QueryLog & IFacadeBase; 6 | -------------------------------------------------------------------------------- /dist/lib/facades/global/QueryLogFacade.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | require("../../query-log/FlipFlopQueryLog"); 5 | const najs_binding_1 = require("najs-binding"); 6 | const najs_facade_1 = require("najs-facade"); 7 | const container_1 = require("../container"); 8 | const constants_1 = require("../../constants"); 9 | const facade = najs_facade_1.Facade.create(container_1.container, 'QueryLog', function () { 10 | return najs_binding_1.make(constants_1.NajsEloquent.QueryLog.FlipFlopQueryLog); 11 | }); 12 | exports.QueryLogFacade = facade; 13 | exports.QueryLog = facade; 14 | -------------------------------------------------------------------------------- /dist/lib/features/EventFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { FeatureBase } from './FeatureBase'; 4 | export declare class EventFeature extends FeatureBase implements NajsEloquent.Feature.IEventFeature { 5 | getPublicApi(): object; 6 | getFeatureName(): string; 7 | getClassName(): string; 8 | fire(model: NajsEloquent.Model.IModel, eventName: string, args: any): Promise; 9 | getEventEmitter(model: NajsEloquent.Model.IModel): Najs.Contracts.Event.AsyncEventEmitter; 10 | getGlobalEventEmitter(model: NajsEloquent.Model.IModel): Najs.Contracts.Event.AsyncEventEmitter; 11 | } 12 | -------------------------------------------------------------------------------- /dist/lib/features/FillableFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { FeatureBase } from './FeatureBase'; 4 | export declare class FillableFeature extends FeatureBase implements NajsEloquent.Feature.IFillableFeature { 5 | getPublicApi(): object; 6 | getFeatureName(): string; 7 | getClassName(): string; 8 | getFillable(model: NajsEloquent.Model.IModel): string[]; 9 | setFillable(model: NajsEloquent.Model.IModel, fillable: string[]): void; 10 | addFillable(model: NajsEloquent.Model.IModel, keys: ArrayLike): void; 11 | isFillable(model: NajsEloquent.Model.IModel, keys: ArrayLike): boolean; 12 | getGuarded(model: NajsEloquent.Model.IModel): string[]; 13 | setGuarded(model: NajsEloquent.Model.IModel, guarded: string[]): void; 14 | addGuarded(model: NajsEloquent.Model.IModel, keys: ArrayLike): void; 15 | isGuarded(model: NajsEloquent.Model.IModel, keys: ArrayLike): boolean; 16 | fill(model: NajsEloquent.Model.IModel, data: object): void; 17 | forceFill(model: NajsEloquent.Model.IModel, data: object): void; 18 | } 19 | -------------------------------------------------------------------------------- /dist/lib/features/QueryFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | import { FeatureBase } from './FeatureBase'; 6 | export declare class QueryFeature extends FeatureBase implements NajsEloquent.Feature.IQueryFeature { 7 | protected factory: NajsEloquent.QueryBuilder.IQueryBuilderFactory; 8 | constructor(factory: NajsEloquent.QueryBuilder.IQueryBuilderFactory); 9 | getPublicApi(): object | undefined; 10 | getFeatureName(): string; 11 | getClassName(): string; 12 | newQuery(model: NajsEloquent.Model.IModel): NajsEloquent.QueryBuilder.IQueryBuilder; 13 | } 14 | -------------------------------------------------------------------------------- /dist/lib/features/SoftDeletesFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { FeatureBase } from './FeatureBase'; 4 | export declare class SoftDeletesFeature extends FeatureBase implements NajsEloquent.Feature.ISoftDeletesFeature { 5 | static DefaultSetting: NajsEloquent.Feature.ISoftDeletesSetting; 6 | getPublicApi(): object; 7 | getFeatureName(): string; 8 | getClassName(): string; 9 | hasSoftDeletes(model: NajsEloquent.Model.IModel): boolean; 10 | getSoftDeletesSetting(model: NajsEloquent.Model.IModel): NajsEloquent.Feature.ISoftDeletesSetting; 11 | trashed(model: NajsEloquent.Model.IModel): boolean; 12 | forceDelete(model: NajsEloquent.Model.IModel): Promise; 13 | restore(model: NajsEloquent.Model.IModel): Promise; 14 | } 15 | -------------------------------------------------------------------------------- /dist/lib/features/TimestampsFeature.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { FeatureBase } from './FeatureBase'; 4 | export declare class TimestampsFeature extends FeatureBase implements NajsEloquent.Feature.ITimestampsFeature { 5 | static DefaultSetting: NajsEloquent.Feature.ITimestampsSetting; 6 | getPublicApi(): object; 7 | getFeatureName(): string; 8 | getClassName(): string; 9 | hasTimestamps(model: NajsEloquent.Model.IModel): boolean; 10 | getTimestampsSetting(model: NajsEloquent.Model.IModel): NajsEloquent.Feature.ITimestampsSetting; 11 | touch(model: NajsEloquent.Model.IModel): void; 12 | } 13 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/EventPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const EventPublicApi: NajsEloquent.Model.IModelEvent; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/EventPublicApi.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.EventPublicApi = { 4 | fire(eventName, args) { 5 | return this.driver.getEventFeature().fire(this, eventName, args); 6 | }, 7 | emit(eventName, eventData, serial) { 8 | return this.driver 9 | .getEventFeature() 10 | .getEventEmitter(this) 11 | .emit(eventName, eventData, serial); 12 | }, 13 | on(eventName, listener) { 14 | this.driver 15 | .getEventFeature() 16 | .getEventEmitter(this) 17 | .on(eventName, listener); 18 | return this; 19 | }, 20 | off(eventName, listener) { 21 | this.driver 22 | .getEventFeature() 23 | .getEventEmitter(this) 24 | .off(eventName, listener); 25 | return this; 26 | }, 27 | once(eventName, listener) { 28 | this.driver 29 | .getEventFeature() 30 | .getEventEmitter(this) 31 | .once(eventName, listener); 32 | return this; 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/FillablePublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const FillablePublicApi: NajsEloquent.Model.IModelFillable; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/RecordManagerPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const RecordManagerPublicApi: NajsEloquent.Model.IModelRecord; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/RelationPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const RelationPublicApi: NajsEloquent.Model.IModelRelation; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/SerializationPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const SerializationPublicApi: NajsEloquent.Model.IModelSerialization; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/SoftDeletesPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const SoftDeletesPublicApi: NajsEloquent.Model.IModelSoftDeletes; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/SoftDeletesPublicApi.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.SoftDeletesPublicApi = { 4 | trashed() { 5 | return this.driver.getSoftDeletesFeature().trashed(this); 6 | }, 7 | forceDelete() { 8 | return this.driver.getSoftDeletesFeature().forceDelete(this); 9 | }, 10 | restore() { 11 | return this.driver.getSoftDeletesFeature().restore(this); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/TimestampsPublicApi.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const TimestampsPublicApi: NajsEloquent.Model.IModelTimestamps; 4 | -------------------------------------------------------------------------------- /dist/lib/features/mixin/TimestampsPublicApi.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.TimestampsPublicApi = { 4 | touch() { 5 | this.driver.getTimestampsFeature().touch(this); 6 | return this; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /dist/lib/model/ModelEvent.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum ModelEvent { 2 | Creating = "creating", 3 | Created = "created", 4 | Saving = "saving", 5 | Saved = "saved", 6 | Updating = "updating", 7 | Updated = "updated", 8 | Deleting = "deleting", 9 | Deleted = "deleted", 10 | Restoring = "restoring", 11 | Restored = "restored" 12 | } 13 | -------------------------------------------------------------------------------- /dist/lib/model/ModelEvent.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var ModelEvent; 4 | (function (ModelEvent) { 5 | ModelEvent["Creating"] = "creating"; 6 | ModelEvent["Created"] = "created"; 7 | ModelEvent["Saving"] = "saving"; 8 | ModelEvent["Saved"] = "saved"; 9 | ModelEvent["Updating"] = "updating"; 10 | ModelEvent["Updated"] = "updated"; 11 | ModelEvent["Deleting"] = "deleting"; 12 | ModelEvent["Deleted"] = "deleted"; 13 | ModelEvent["Restoring"] = "restoring"; 14 | ModelEvent["Restored"] = "restored"; 15 | })(ModelEvent = exports.ModelEvent || (exports.ModelEvent = {})); 16 | -------------------------------------------------------------------------------- /dist/lib/model/ModelProxyHandler.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import Model = NajsEloquent.Model.ModelInternal; 3 | export declare const ModelProxyHandler: ProxyHandler; 4 | -------------------------------------------------------------------------------- /dist/lib/model/ModelProxyHandler.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | exports.ModelProxyHandler = { 5 | get(target, key) { 6 | if (target.driver.shouldBeProxied(target, key)) { 7 | return target.driver.proxify('get', target, key); 8 | } 9 | return target[key]; 10 | }, 11 | set(target, key, value) { 12 | if (target.driver.shouldBeProxied(target, key)) { 13 | return target.driver.proxify('set', target, key, value); 14 | } 15 | target[key] = value; 16 | return true; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /dist/lib/providers/DriverProvider.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import Driver = Najs.Contracts.Eloquent.Driver; 3 | import { Facade } from 'najs-facade'; 4 | export declare class DriverProvider extends Facade implements Najs.Contracts.Eloquent.DriverProvider { 5 | static className: string; 6 | protected drivers: { 7 | [key: string]: { 8 | driverClassName: string; 9 | isDefault: boolean; 10 | }; 11 | }; 12 | protected driverInstances: { 13 | [key: string]: any; 14 | }; 15 | protected binding: { 16 | [key: string]: string; 17 | }; 18 | getClassName(): string; 19 | protected findDefaultDriver(): string; 20 | protected createDriver(model: Object, driverClass: string, isGuarded: boolean): Driver; 21 | has(driver: Function): boolean; 22 | create(model: Object, isGuarded?: boolean): Driver; 23 | findDriverClassName(model: Object | string): string; 24 | register(driver: string | Function, name: string, isDefault?: boolean): this; 25 | bind(model: string, driver: string): this; 26 | } 27 | -------------------------------------------------------------------------------- /dist/lib/providers/MomentProvider.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { Moment } from 'moment'; 3 | import { Facade } from 'najs-facade'; 4 | export declare class MomentProvider extends Facade implements Najs.Contracts.Eloquent.MomentProvider { 5 | getClassName(): string; 6 | make(): Moment; 7 | isMoment(value: any): boolean; 8 | setNow(cb: () => any): this; 9 | } 10 | -------------------------------------------------------------------------------- /dist/lib/providers/MomentProvider.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const najs_binding_1 = require("najs-binding"); 5 | const najs_facade_1 = require("najs-facade"); 6 | const constants_1 = require("../constants"); 7 | const moment = require('moment'); 8 | class MomentProvider extends najs_facade_1.Facade { 9 | getClassName() { 10 | return constants_1.NajsEloquent.Provider.MomentProvider; 11 | } 12 | make() { 13 | return moment(...arguments); 14 | } 15 | isMoment(value) { 16 | return moment.isMoment(value); 17 | } 18 | setNow(cb) { 19 | moment.now = cb; 20 | return this; 21 | } 22 | } 23 | exports.MomentProvider = MomentProvider; 24 | najs_binding_1.register(MomentProvider, constants_1.NajsEloquent.Provider.MomentProvider); 25 | -------------------------------------------------------------------------------- /dist/lib/query-builders/QueryBuilder.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import IQueryBuilder = NajsEloquent.QueryBuilder.IQueryBuilder; 4 | import { QueryBuilderHandlerBase } from './QueryBuilderHandlerBase'; 5 | export interface QueryBuilder extends IQueryBuilder { 6 | } 7 | export declare class QueryBuilder { 8 | protected handler: H; 9 | constructor(handler: H); 10 | } 11 | -------------------------------------------------------------------------------- /dist/lib/query-builders/QueryBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const Query_1 = require("./mixin/Query"); 4 | const ConditionQuery_1 = require("./mixin/ConditionQuery"); 5 | const ExecuteQuery_1 = require("./mixin/ExecuteQuery"); 6 | const AdvancedQuery_1 = require("./mixin/AdvancedQuery"); 7 | const RelationQuery_1 = require("./mixin/RelationQuery"); 8 | class QueryBuilder { 9 | constructor(handler) { 10 | this.handler = handler; 11 | } 12 | } 13 | exports.QueryBuilder = QueryBuilder; 14 | Object.assign(QueryBuilder.prototype, Query_1.Query, ConditionQuery_1.ConditionQuery, ExecuteQuery_1.ExecuteQuery, AdvancedQuery_1.AdvancedQuery, RelationQuery_1.RelationQuery); 15 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/AdvancedQuery.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const AdvancedQuery: NajsEloquent.QueryGrammar.IAdvancedQuery; 4 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/ConditionQuery.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const ConditionQuery: NajsEloquent.QueryGrammar.IConditionQuery; 4 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/ExecuteQuery.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | export declare const ExecuteQuery: NajsEloquent.QueryGrammar.IExecuteQuery; 4 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/ExecuteQuery.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | /// 4 | Object.defineProperty(exports, "__esModule", { value: true }); 5 | exports.ExecuteQuery = { 6 | async count() { 7 | return this.handler.getQueryExecutor().count(); 8 | }, 9 | async update(data) { 10 | return this.handler.getQueryExecutor().update(this); 11 | }, 12 | async delete() { 13 | return this.handler.getQueryExecutor().delete(); 14 | }, 15 | async restore() { 16 | return this.handler.getQueryExecutor().restore(); 17 | }, 18 | async execute() { 19 | return this.handler.getQueryExecutor().execute(); 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/Query.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare const Query: NajsEloquent.QueryGrammar.IQuery; 3 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/RelationQuery.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare const RelationQuery: NajsEloquent.QueryGrammar.IRelationQuery; 3 | -------------------------------------------------------------------------------- /dist/lib/query-builders/mixin/RelationQuery.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const lodash_1 = require("lodash"); 4 | exports.RelationQuery = { 5 | with(...relations) { 6 | this.handler.setEagerRelations(lodash_1.flatten(relations)); 7 | return this; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/DefaultConvention.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare class DefaultConvention implements NajsEloquent.QueryBuilder.IConvention { 3 | formatFieldName(name: any): any; 4 | getNullValueFor(name: any): null; 5 | } 6 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/DefaultConvention.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | class DefaultConvention { 5 | formatFieldName(name) { 6 | return name; 7 | } 8 | getNullValueFor(name) { 9 | // tslint:disable-next-line 10 | return null; 11 | } 12 | } 13 | exports.DefaultConvention = DefaultConvention; 14 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/ExecutorUtils.d.ts: -------------------------------------------------------------------------------- 1 | import { QueryBuilderHandlerBase } from '../QueryBuilderHandlerBase'; 2 | export declare class ExecutorUtils { 3 | static addSoftDeleteConditionIfNeeded(handler: QueryBuilderHandlerBase): void; 4 | } 5 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/ExecutorUtils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | class ExecutorUtils { 4 | static addSoftDeleteConditionIfNeeded(handler) { 5 | if (handler.shouldAddSoftDeleteCondition()) { 6 | const settings = handler.getSoftDeletesSetting(); 7 | handler.getConditionQuery().whereNull(settings.deletedAt); 8 | handler.markSoftDeleteState('added'); 9 | } 10 | } 11 | } 12 | exports.ExecutorUtils = ExecutorUtils; 13 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/Operator.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum Operator { 2 | And = "and", 3 | Or = "or", 4 | GreaterThan = ">", 5 | LessThan = "<", 6 | Equals = "=", 7 | NotEquals = "<>", 8 | GreaterThanOrEquals = ">=", 9 | LessThanOrEquals = "<=", 10 | In = "in", 11 | NotIn = "not-in" 12 | } 13 | -------------------------------------------------------------------------------- /dist/lib/query-builders/shared/Operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var Operator; 4 | (function (Operator) { 5 | Operator["And"] = "and"; 6 | Operator["Or"] = "or"; 7 | Operator["GreaterThan"] = ">"; 8 | Operator["LessThan"] = "<"; 9 | Operator["Equals"] = "="; 10 | Operator["NotEquals"] = "<>"; 11 | Operator["GreaterThanOrEquals"] = ">="; 12 | Operator["LessThanOrEquals"] = "<="; 13 | Operator["In"] = "in"; 14 | Operator["NotIn"] = "not-in"; 15 | })(Operator = exports.Operator || (exports.Operator = {})); 16 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationData.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare class RelationData implements NajsEloquent.Relation.IRelationData { 3 | protected data: T | undefined | null; 4 | protected state: string; 5 | protected factory: NajsEloquent.Relation.IRelationshipFactory; 6 | protected loadType?: 'lazy' | 'eager'; 7 | constructor(factory: NajsEloquent.Relation.IRelationshipFactory); 8 | getFactory(): NajsEloquent.Relation.IRelationshipFactory; 9 | isLoaded(): boolean; 10 | hasData(): boolean; 11 | getData(): T | undefined | null; 12 | setData(data: T | undefined | null): T | undefined | null; 13 | getLoadType(): 'unknown' | 'lazy' | 'eager'; 14 | setLoadType(type: 'lazy' | 'eager'): this; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | class RelationData { 5 | constructor(factory) { 6 | this.factory = factory; 7 | this.state = 'unload'; 8 | } 9 | getFactory() { 10 | return this.factory; 11 | } 12 | isLoaded() { 13 | return this.state === 'loaded' || this.state === 'collected'; 14 | } 15 | hasData() { 16 | return this.state === 'collected'; 17 | } 18 | getData() { 19 | return this.data; 20 | } 21 | setData(data) { 22 | this.data = data; 23 | this.state = 'collected'; 24 | return data; 25 | } 26 | getLoadType() { 27 | return this.loadType || 'unknown'; 28 | } 29 | setLoadType(type) { 30 | this.loadType = type; 31 | this.state = 'loaded'; 32 | return this; 33 | } 34 | } 35 | exports.RelationData = RelationData; 36 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationDataBucket.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import Model = NajsEloquent.Model.IModel; 4 | import IRelationDataBucket = NajsEloquent.Relation.IRelationDataBucket; 5 | import IRelationDataBucketMetadata = NajsEloquent.Relation.IRelationDataBucketMetadata; 6 | import Autoload = Najs.Contracts.Autoload; 7 | import { DataBuffer } from '../data/DataBuffer'; 8 | export declare class RelationDataBucket implements Autoload, IRelationDataBucket { 9 | protected bucket: { 10 | [key in string]: { 11 | data: DataBuffer; 12 | meta: { 13 | loaded: string[]; 14 | }; 15 | }; 16 | }; 17 | constructor(); 18 | getClassName(): string; 19 | add(model: Model): this; 20 | makeModel(model: M, data: any): M; 21 | makeCollection(model: M, data: any[]): CollectJs.Collection; 22 | getDataOf(model: M): DataBuffer; 23 | getMetadataOf(model: Model): IRelationDataBucketMetadata; 24 | createKey(model: Model): string; 25 | } 26 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationDefinitionFinder.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import IModel = NajsEloquent.Model.IModel; 4 | import RelationDefinition = NajsEloquent.Relation.RelationDefinition; 5 | export declare class RelationDefinitionFinder { 6 | model: IModel; 7 | prototype: object; 8 | bases: object[]; 9 | constructor(model: IModel, prototype: object, bases: object[]); 10 | getDefinitions(): {}; 11 | findDefinitionsInPrototype(prototype: object): {}; 12 | findDefinition(target: string, descriptor: PropertyDescriptor, className?: string): RelationDefinition | undefined; 13 | warning(definition: RelationDefinition, definedDefinition: RelationDefinition): void; 14 | formatTargetName(definition: RelationDefinition): string; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationshipType.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum RelationshipType { 2 | HasOne = "HasOne", 3 | HasMany = "HasMany", 4 | BelongsTo = "BelongsTo", 5 | BelongsToMany = "BelongsToMany", 6 | MorphOne = "MorphOne", 7 | MorphMany = "MorphMany", 8 | MorphTo = "MorphTo" 9 | } 10 | -------------------------------------------------------------------------------- /dist/lib/relations/RelationshipType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var RelationshipType; 4 | (function (RelationshipType) { 5 | RelationshipType["HasOne"] = "HasOne"; 6 | RelationshipType["HasMany"] = "HasMany"; 7 | RelationshipType["BelongsTo"] = "BelongsTo"; 8 | RelationshipType["BelongsToMany"] = "BelongsToMany"; 9 | RelationshipType["MorphOne"] = "MorphOne"; 10 | RelationshipType["MorphMany"] = "MorphMany"; 11 | RelationshipType["MorphTo"] = "MorphTo"; 12 | })(RelationshipType = exports.RelationshipType || (exports.RelationshipType = {})); 13 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/BelongsTo.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import Model = NajsEloquent.Model.IModel; 5 | import IBelongsToRelationship = NajsEloquent.Relation.IBelongsToRelationship; 6 | import { HasOneOrMany } from './HasOneOrMany'; 7 | import { HasOneExecutor } from './executors/HasOneExecutor'; 8 | export declare class BelongsTo extends HasOneOrMany implements IBelongsToRelationship { 9 | static className: string; 10 | protected executor: HasOneExecutor; 11 | getClassName(): string; 12 | getType(): string; 13 | getExecutor(): HasOneExecutor; 14 | dissociate(): void; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/HasMany.d.ts: -------------------------------------------------------------------------------- 1 | import Model = NajsEloquent.Model.IModel; 2 | import IHasManyRelationship = NajsEloquent.Relation.IHasManyRelationship; 3 | import Collection = CollectJs.Collection; 4 | import { HasOneOrMany } from './HasOneOrMany'; 5 | import { HasManyExecutor } from './executors/HasManyExecutor'; 6 | export declare class HasMany extends HasOneOrMany> implements IHasManyRelationship { 7 | static className: string; 8 | protected executor: HasManyExecutor; 9 | getClassName(): string; 10 | getType(): string; 11 | getExecutor(): HasManyExecutor; 12 | associate(...models: Array>): this; 13 | dissociate(...models: Array>): this; 14 | } 15 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/HasOne.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | import Model = NajsEloquent.Model.IModel; 5 | import IHasOneRelationship = NajsEloquent.Relation.IHasOneRelationship; 6 | import { HasOneOrMany } from './HasOneOrMany'; 7 | import { HasOneExecutor } from './executors/HasOneExecutor'; 8 | export declare class HasOne extends HasOneOrMany implements IHasOneRelationship { 9 | static className: string; 10 | protected executor: HasOneExecutor; 11 | getClassName(): string; 12 | getType(): string; 13 | getExecutor(): HasOneExecutor; 14 | associate(model: T): void; 15 | } 16 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/executors/HasManyExecutor.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | import IModel = NajsEloquent.Model.IModel; 7 | import IRelationDataBucket = NajsEloquent.Relation.IRelationDataBucket; 8 | import Collection = CollectJs.Collection; 9 | import { HasOneOrManyExecutor } from './HasOneOrManyExecutor'; 10 | export declare class HasManyExecutor extends HasOneOrManyExecutor> { 11 | protected dataBucket: IRelationDataBucket; 12 | protected targetModel: IModel; 13 | executeQuery(): Promise | undefined | null>; 14 | executeCollector(): Collection | undefined | null; 15 | getEmptyValue(): Collection | undefined; 16 | } 17 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/executors/HasManyExecutor.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | Object.defineProperty(exports, "__esModule", { value: true }); 8 | const factory_1 = require("../../../util/factory"); 9 | const HasOneOrManyExecutor_1 = require("./HasOneOrManyExecutor"); 10 | class HasManyExecutor extends HasOneOrManyExecutor_1.HasOneOrManyExecutor { 11 | async executeQuery() { 12 | return this.query.get(); 13 | } 14 | executeCollector() { 15 | return this.dataBucket.makeCollection(this.targetModel, this.collector.exec()); 16 | } 17 | getEmptyValue() { 18 | return factory_1.make_collection([]); 19 | } 20 | } 21 | exports.HasManyExecutor = HasManyExecutor; 22 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/executors/HasOneExecutor.d.ts: -------------------------------------------------------------------------------- 1 | import { HasOneOrManyExecutor } from './HasOneOrManyExecutor'; 2 | export declare class HasOneExecutor extends HasOneOrManyExecutor { 3 | executeQuery(): Promise; 4 | executeCollector(): T | undefined | null; 5 | getEmptyValue(): T | undefined; 6 | } 7 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/executors/HasOneExecutor.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const HasOneOrManyExecutor_1 = require("./HasOneOrManyExecutor"); 4 | class HasOneExecutor extends HasOneOrManyExecutor_1.HasOneOrManyExecutor { 5 | async executeQuery() { 6 | return this.query.first(); 7 | } 8 | executeCollector() { 9 | this.collector.limit(1); 10 | const result = this.collector.exec(); 11 | if (result.length === 0) { 12 | return undefined; 13 | } 14 | return this.dataBucket.makeModel(this.targetModel, result[0]); 15 | } 16 | getEmptyValue() { 17 | return undefined; 18 | } 19 | } 20 | exports.HasOneExecutor = HasOneExecutor; 21 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/executors/HasOneOrManyExecutor.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | /// 4 | /// 5 | /// 6 | Object.defineProperty(exports, "__esModule", { value: true }); 7 | class HasOneOrManyExecutor { 8 | constructor(dataBucket, targetModel) { 9 | this.dataBucket = dataBucket; 10 | this.targetModel = targetModel; 11 | } 12 | setCollector(collector, conditions, reader) { 13 | this.collector = collector; 14 | this.collector.filterBy({ $and: conditions }); 15 | return this; 16 | } 17 | setQuery(query) { 18 | this.query = query; 19 | return this; 20 | } 21 | } 22 | exports.HasOneOrManyExecutor = HasOneOrManyExecutor; 23 | -------------------------------------------------------------------------------- /dist/lib/relations/relationships/pivot/PivotModel.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import IPivotOptions = NajsEloquent.Relation.IPivotOptions; 3 | import { Model } from '../../../model/Model'; 4 | export declare class PivotModel extends Model { 5 | /** 6 | * Make new Pivot Model type 7 | * 8 | * @param modelName 9 | */ 10 | static createPivotClass(modelName: string, options: IPivotOptions, className?: string): typeof PivotModel; 11 | } 12 | -------------------------------------------------------------------------------- /dist/lib/util/PrototypeManager.d.ts: -------------------------------------------------------------------------------- 1 | export declare const PrototypeManager: { 2 | stopFindingRelationsPrototypes: Object[]; 3 | stopFindingRelationsIn(prototype: object): void; 4 | shouldFindRelationsIn(prototype: object): boolean; 5 | }; 6 | -------------------------------------------------------------------------------- /dist/lib/util/PrototypeManager.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.PrototypeManager = { 4 | stopFindingRelationsPrototypes: [Object.prototype], 5 | stopFindingRelationsIn(prototype) { 6 | if (this.shouldFindRelationsIn(prototype)) { 7 | this.stopFindingRelationsPrototypes.push(prototype); 8 | } 9 | }, 10 | shouldFindRelationsIn(prototype) { 11 | for (const item of this.stopFindingRelationsPrototypes) { 12 | if (item === prototype) { 13 | return false; 14 | } 15 | } 16 | return true; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /dist/lib/util/SettingType.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare class SettingType { 3 | static arrayUnique(initializeValue: T[], defaultValue: T[]): NajsEloquent.Util.ISettingReader; 4 | } 5 | -------------------------------------------------------------------------------- /dist/lib/util/SettingType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const functions_1 = require("./functions"); 5 | class SettingType { 6 | static arrayUnique(initializeValue, defaultValue) { 7 | return function (staticValue, sampleValue, instanceValue) { 8 | if (!staticValue && !sampleValue && !instanceValue) { 9 | return defaultValue; 10 | } 11 | const values = initializeValue 12 | .concat(staticValue ? staticValue : []) 13 | .concat(sampleValue ? sampleValue : []) 14 | .concat(instanceValue ? instanceValue : []); 15 | const result = functions_1.array_unique(values); 16 | if (result.length === 0) { 17 | return defaultValue; 18 | } 19 | return result; 20 | }; 21 | } 22 | } 23 | exports.SettingType = SettingType; 24 | -------------------------------------------------------------------------------- /dist/lib/util/accessors.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare function relationFeatureOf(model: NajsEloquent.Model.IModel): NajsEloquent.Feature.IRelationFeature; 3 | -------------------------------------------------------------------------------- /dist/lib/util/accessors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | function relationFeatureOf(model) { 5 | return model.getDriver().getRelationFeature(); 6 | } 7 | exports.relationFeatureOf = relationFeatureOf; 8 | -------------------------------------------------------------------------------- /dist/lib/util/factory.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export declare function make_collection(data: object): CollectJs.Collection; 3 | export declare function make_collection(data: T[]): CollectJs.Collection; 4 | export declare function make_collection(data: T[], converter: (item: T) => R): CollectJs.Collection; 5 | -------------------------------------------------------------------------------- /dist/lib/util/factory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const collect = require('collect.js'); 5 | function make_collection(data, converter) { 6 | if (typeof converter === 'undefined') { 7 | return collect(data); 8 | } 9 | return collect(data.map(converter)); 10 | } 11 | exports.make_collection = make_collection; 12 | -------------------------------------------------------------------------------- /dist/lib/util/functions.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Check the given key is in the array or not 3 | * 4 | * @param {mixed} key 5 | * @param {mixed[]} args 6 | */ 7 | export declare function in_array(key: T, ...args: T[][]): boolean; 8 | /** 9 | * Return new array which filter duplicated item in given array. 10 | * 11 | * @param {mixed[]} array 12 | */ 13 | export declare function array_unique(...array: Array>): T[]; 14 | export declare function find_base_prototypes(prototype: Object, root: Object): Object[]; 15 | export declare type DotNotationInfo = { 16 | first: string; 17 | last: string; 18 | afterFirst: string; 19 | beforeLast: string; 20 | parts: string[]; 21 | }; 22 | export declare function parse_string_with_dot_notation(input: string): DotNotationInfo; 23 | export declare function override_setting_property_of_model(model: object, property: string, values: string[]): void; 24 | -------------------------------------------------------------------------------- /dist/lib/util/helpers.d.ts: -------------------------------------------------------------------------------- 1 | import { Model } from '../model/Model'; 2 | export declare function isModel(value: any): boolean; 3 | export declare function isObjectId(value: any): boolean; 4 | export declare function isCollection(value: any): boolean; 5 | export declare function distinctModelByClassInCollection(collection: CollectJs.Collection): Model[]; 6 | -------------------------------------------------------------------------------- /dist/lib/util/isPromise.d.ts: -------------------------------------------------------------------------------- 1 | export declare function isPromise(obj: any): boolean; 2 | -------------------------------------------------------------------------------- /dist/lib/util/isPromise.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | function isPromise(obj) { 4 | return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; 5 | } 6 | exports.isPromise = isPromise; 7 | -------------------------------------------------------------------------------- /dist/test/_integration/model/ModelEvent.integration.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/model/ModelFillable.integration.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/model/ModelSerialization.integration.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/BelongsToMany.softDeletes.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/BelongsToMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/BelongsToMany.timestamps.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/HasMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/HasOne.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/ManyToMany.PivotDefinition.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/MorphMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_integration/relation/MorphOne.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/_syntax/Factory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/data/DataBuffer.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/data/DataCollector.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/data/DataConditionMatcher.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/DriverBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/ExecutorBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/QueryLogBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../lib/query-log/FlipFlopQueryLog'; 3 | -------------------------------------------------------------------------------- /dist/test/drivers/Record.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordConditionMatcher.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordConditionMatcherFactory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordDataReader.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordDataSourceBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordExecutorBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordManager.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/RecordManagerBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryDataSource.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryExecutorFactory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryBuilder.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryBuilder.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | const QueryBuilder_1 = require("../../../lib/query-builders/QueryBuilder"); 5 | const MemoryQueryBuilder_1 = require("../../../lib/drivers/memory/MemoryQueryBuilder"); 6 | const MemoryQueryBuilderHandler_1 = require("../../../lib/drivers/memory/MemoryQueryBuilderHandler"); 7 | const MemoryDataSource_1 = require("../../../lib/drivers/memory/MemoryDataSource"); 8 | const MemoryDataSourceProviderFacade_1 = require("../../../lib/facades/global/MemoryDataSourceProviderFacade"); 9 | MemoryDataSourceProviderFacade_1.MemoryDataSourceProvider.register(MemoryDataSource_1.MemoryDataSource, 'memory', true); 10 | describe('MemoryQueryBuilder', function () { 11 | it('extends QueryBuilder', function () { 12 | const model = {}; 13 | const instance = new MemoryQueryBuilder_1.MemoryQueryBuilder(new MemoryQueryBuilderHandler_1.MemoryQueryBuilderHandler(model)); 14 | expect(instance).toBeInstanceOf(QueryBuilder_1.QueryBuilder); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryBuilderFactory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryBuilderHandler.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryQueryLog.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/drivers/memory/MemoryRecordExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/facades/container.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/facades/container.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | const najs_facade_1 = require("najs-facade"); 5 | const container_1 = require("../../lib/facades/container"); 6 | describe('Najs Facade Container', function () { 7 | it('is an instance of FacadeContainer, it has global reference called "NajsEloquent"', function () { 8 | expect(container_1.container).toBeInstanceOf(najs_facade_1.FacadeContainer); 9 | expect(global['NajsEloquent'] === container_1.container).toBe(true); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /dist/test/facades/global/EloquentDriverProviderFacade.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../../lib/providers/DriverProvider'; 3 | -------------------------------------------------------------------------------- /dist/test/facades/global/EloquentDriverProviderFacade.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | require("../../../lib/providers/DriverProvider"); 5 | const NajsBinding = require("najs-binding"); 6 | const Sinon = require("sinon"); 7 | const constants_1 = require("../../../lib/constants"); 8 | const DriverProviderFacade_1 = require("../../../lib/facades/global/DriverProviderFacade"); 9 | describe('DriverProviderFacade', function () { 10 | it('calls make() to create new instance of DriverProvider as a facade root', function () { 11 | const makeSpy = Sinon.spy(NajsBinding, 'make'); 12 | DriverProviderFacade_1.DriverProviderFacade.reloadFacadeRoot(); 13 | expect(makeSpy.calledWith(constants_1.NajsEloquent.Provider.DriverProvider)).toBe(true); 14 | expect(makeSpy.calledOnce).toBe(true); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /dist/test/facades/global/FactoryFacade.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../../lib/factory/FactoryManager'; 3 | -------------------------------------------------------------------------------- /dist/test/facades/global/MemoryDataSourceProviderFacade.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../../lib/drivers/memory/MemoryDataSource'; 3 | -------------------------------------------------------------------------------- /dist/test/facades/global/MemoryDataSourceProviderFacade.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | require("../../../lib/drivers/memory/MemoryDataSource"); 5 | const NajsBinding = require("najs-binding"); 6 | const Sinon = require("sinon"); 7 | const constants_1 = require("../../../lib/constants"); 8 | const MemoryDataSourceProviderFacade_1 = require("../../../lib/facades/global/MemoryDataSourceProviderFacade"); 9 | describe('MemoryDataSourceProviderFacade', function () { 10 | it('calls make() to create new instance of MemoryDataSourceFacade as a facade root', function () { 11 | const makeSpy = Sinon.spy(NajsBinding, 'make'); 12 | MemoryDataSourceProviderFacade_1.MemoryDataSourceProviderFacade.reloadFacadeRoot(); 13 | expect(makeSpy.calledWith(constants_1.NajsEloquent.Provider.MemoryDataSourceProvider)).toBe(true); 14 | expect(makeSpy.calledOnce).toBe(true); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /dist/test/facades/global/MomentProviderFacade.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../../lib/providers/MomentProvider'; 3 | -------------------------------------------------------------------------------- /dist/test/facades/global/MomentProviderFacade.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | require("../../../lib/providers/MomentProvider"); 5 | const NajsBinding = require("najs-binding"); 6 | const Sinon = require("sinon"); 7 | const constants_1 = require("../../../lib/constants"); 8 | const MomentProviderFacade_1 = require("../../../lib/facades/global/MomentProviderFacade"); 9 | describe('MomentProviderFacade', function () { 10 | it('calls make() to create new instance of MomentFacade as a facade root', function () { 11 | const makeSpy = Sinon.spy(NajsBinding, 'make'); 12 | MomentProviderFacade_1.MomentProviderFacade.reloadFacadeRoot(); 13 | expect(makeSpy.calledWith(constants_1.NajsEloquent.Provider.MomentProvider)).toBe(true); 14 | expect(makeSpy.calledOnce).toBe(true); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /dist/test/facades/global/QueryLogFacade.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | import '../../../lib/query-log/FlipFlopQueryLog'; 3 | -------------------------------------------------------------------------------- /dist/test/facades/global/QueryLogFacade.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | require("../../../lib/query-log/FlipFlopQueryLog"); 5 | const NajsBinding = require("najs-binding"); 6 | const Sinon = require("sinon"); 7 | const constants_1 = require("../../../lib/constants"); 8 | const QueryLogFacade_1 = require("../../../lib/facades/global/QueryLogFacade"); 9 | describe('QueryLogFacade', function () { 10 | it('calls make() to create new instance of FlipFlopQueryLog as a facade root', function () { 11 | const makeSpy = Sinon.spy(NajsBinding, 'make'); 12 | QueryLogFacade_1.QueryLogFacade.reloadFacadeRoot(); 13 | expect(makeSpy.calledWith(constants_1.NajsEloquent.QueryLog.FlipFlopQueryLog)).toBe(true); 14 | expect(makeSpy.calledOnce).toBe(true); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /dist/test/factory/FactoryBuilder.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/factory/FactoryManager.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/EventFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/FeatureBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/FillableFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/QueryFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/RelationFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/SerializationFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/SettingFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/SoftDeletesFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/TimestampsFeature.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/EventPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/FillablePublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/RecordManagerPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/RelationPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/SerializationPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/SoftDeletesPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/TimestampsPublicApi.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/features/mixin/TimestampsPublicApi.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | const Sinon = require("sinon"); 5 | const TimestampsPublicApi_1 = require("../../../lib/features/mixin/TimestampsPublicApi"); 6 | describe('TimestampsPublicApi', function () { 7 | const timestampsFeature = { 8 | touch() { 9 | return 'touch-result'; 10 | } 11 | }; 12 | const model = { 13 | driver: { 14 | getTimestampsFeature() { 15 | return timestampsFeature; 16 | } 17 | } 18 | }; 19 | describe('.touch()', function () { 20 | it('is chainable, calls TimestampsFeature.touch()', function () { 21 | const stub = Sinon.stub(timestampsFeature, 'touch'); 22 | stub.returns('anything'); 23 | expect(TimestampsPublicApi_1.TimestampsPublicApi.touch.call(model) === model).toBe(true); 24 | expect(stub.calledWith(model)).toBe(true); 25 | stub.restore(); 26 | }); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /dist/test/model/Model.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/model/ModelProxyHandler.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/providers/DriverProvider.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/providers/MemoryDataSourceProvider.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/providers/MomentProvider.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/QueryBuilder.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/QueryBuilderHandlerBase.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/AdvancedQuery.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/ConditionQuery.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/ExecuteQuery.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/Query.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/RelationQuery.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/mixin/RelationQuery.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | const Sinon = require("sinon"); 5 | const RelationQuery_1 = require("../../../lib/query-builders/mixin/RelationQuery"); 6 | describe('RelationQuery', function () { 7 | describe('.with()', function () { 8 | it('flattens argument and calls handler.setEagerRelations() then returns this', function () { 9 | const queryBuilder = { 10 | handler: { 11 | setEagerRelations() { } 12 | } 13 | }; 14 | const spy = Sinon.spy(queryBuilder.handler, 'setEagerRelations'); 15 | expect(RelationQuery_1.RelationQuery.with.apply(queryBuilder, ['a', ['b', 'c'], 'd']) === queryBuilder).toBe(true); 16 | expect(spy.calledWith(['a', 'b', 'c', 'd'])).toBe(true); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/BasicQuery.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/BasicQueryConverter.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/ConditionQueryHandler.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/DefaultConvention.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/ExecutorUtils.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-builders/shared/QueryCondition.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/query-log/FlipFlopQueryLog.test.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import 'jest'; 3 | -------------------------------------------------------------------------------- /dist/test/relations/RelationData.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/RelationDataBucket.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/RelationDenifitionFinder.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/RelationUtilities.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/Relationship.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/RelationshipFactory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/BelongsTo.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/BelongsToMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/HasMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/HasOne.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/HasOneOrMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/ManyToMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/MorphMany.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/MorphOne.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/MorphTo.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/executors/HasManyExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/executors/HasOneExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/executors/HasOneOrManyExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/executors/MorphOneOrManyExecutor.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/relations/relationships/pivot/PivotModel.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/ClassSetting.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/PrototypeManager.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/SettingType.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/factory.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/factory.test.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | require("jest"); 4 | const factory_1 = require("../../lib/util/factory"); 5 | const collect = require('collect.js'); 6 | const CollectionPrototype = Object.getPrototypeOf(collect([])); 7 | describe('make_collection()', function () { 8 | it('makes an instance of collection from collect() of the collect.js library', function () { 9 | const data = [1, 2, 3]; 10 | const result = factory_1.make_collection(data); 11 | expect(result.all() === data).toBe(true); 12 | expect(Object.getPrototypeOf(result) === CollectionPrototype).toBe(true); 13 | }); 14 | it('maps to convert data and make an instance of collection from the collect.js library', function () { 15 | const data = [1, 2, 3]; 16 | const result = factory_1.make_collection(data, i => i * 2); 17 | expect(result.all() === data).toBe(false); 18 | expect(result.all()).toEqual([2, 4, 6]); 19 | expect(Object.getPrototypeOf(result) === CollectionPrototype).toBe(true); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /dist/test/util/functions.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/helpers.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /dist/test/util/isPromise.test.d.ts: -------------------------------------------------------------------------------- 1 | import 'jest'; 2 | -------------------------------------------------------------------------------- /lib/contracts/FactoryBuilder.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace Najs.Contracts.Eloquent { 4 | export interface FactoryBuilder { 5 | /** 6 | * Set the amount of models you wish to create / make. 7 | * 8 | * @param {number} amount 9 | */ 10 | times(amount: number): Pick>, 'create' | 'states' | 'make' | 'raw'> 11 | 12 | /** 13 | * Set the states to be applied to the model. 14 | * 15 | * @param {string|string[]} state 16 | */ 17 | states(...state: Array): this 18 | 19 | /** 20 | * Create an instance of model and persist them to the database. 21 | * @param {Object} attributes 22 | */ 23 | create(attributes?: Object): Promise 24 | 25 | /** 26 | * Create an instance of model. 27 | * 28 | * @param {Object} attributes 29 | */ 30 | make(attributes?: Object): T 31 | 32 | /** 33 | * Create a raw attribute array. 34 | * 35 | * @param {Object} attributes 36 | */ 37 | raw(attributes?: Object): T 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/contracts/MemoryDataSource.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | namespace Najs.Contracts.Eloquent { 6 | export interface MemoryDataSource 7 | extends Najs.Contracts.Autoload, 8 | NajsEloquent.Data.IDataBuffer { 9 | /** 10 | * Read data from data source to buffer. 11 | */ 12 | read(): Promise 13 | 14 | /** 15 | * Write buffer to data source. 16 | */ 17 | write(): Promise 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/contracts/MomentProvider.ts: -------------------------------------------------------------------------------- 1 | namespace Najs.Contracts.Eloquent { 2 | export interface MomentProvider extends Najs.Contracts.Autoload { 3 | /** 4 | * Make moment instance 5 | */ 6 | make(...args: any[]): T 7 | 8 | /** 9 | * Determine that the given value is Moment or not 10 | */ 11 | isMoment(value: any): boolean 12 | 13 | /** 14 | * Set now value to the Moment instance 15 | */ 16 | setNow(cb: () => any): this 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/definitions/data/IDataReader.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Data { 2 | export interface IDataReader { 3 | /** 4 | * Get an attribute of data. 5 | * 6 | * @param {T} data 7 | * @param {string} field 8 | */ 9 | getAttribute(data: T, field: string): R 10 | 11 | /** 12 | * Pick some fields in data. 13 | * 14 | * @param {object} data 15 | * @param {string[]} fields 16 | */ 17 | pick(data: T, fields: string[]): T 18 | 19 | /** 20 | * Convert give value to comparable value if needed, typically convert value like ObjectID to string. 21 | * 22 | * @param {mixed} value 23 | */ 24 | toComparable(value: any): R 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/definitions/driver/IExecutor.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Driver { 2 | export interface IExecutor { 3 | /** 4 | * Set execute mode, can set to "disabled" then nothing will executed in db. 5 | * 6 | * @param {string} mode 7 | */ 8 | setExecuteMode(mode: 'default' | 'disabled'): this 9 | 10 | /** 11 | * Determine that should execute a query/command or not. 12 | */ 13 | shouldExecute(): boolean 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/definitions/driver/IExecutorFactory.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.Driver { 5 | export interface IExecutorFactory { 6 | makeRecordExecutor(model: Model.ModelInternal, record: any): Feature.IRecordExecutor 7 | 8 | makeQueryExecutor(handler: QueryBuilder.IQueryBuilderHandler): QueryBuilder.IQueryExecutor 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/definitions/factory/IFactoryDefinition.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Factory { 4 | export interface IFactoryDefinition { 5 | (faker: Chance.Chance, attributes?: object): object 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lib/definitions/features/IFeature.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.Feature { 5 | export interface IFeature extends Najs.Contracts.Autoload { 6 | /** 7 | * Attach the public api to prototype of model, it also applies the shared properties to all model instances. 8 | * 9 | * @param {object} prototype 10 | * @param {object[]} bases 11 | * @param {Driver} driver 12 | */ 13 | attachPublicApi(prototype: object, bases: object[], driver: Najs.Contracts.Eloquent.Driver): void 14 | 15 | /** 16 | * Get the feature name. 17 | */ 18 | getFeatureName(): string 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/definitions/features/IQueryFeature.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.Feature { 5 | export interface IQueryFeature extends IFeature { 6 | /** 7 | * Create new query builder for model. 8 | */ 9 | newQuery(model: M): NajsEloquent.QueryBuilder.IQueryBuilder 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/definitions/features/IRecordExecutor.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.Feature { 5 | export interface IRecordExecutor extends Driver.IExecutor { 6 | /** 7 | * Execute create for record and model. 8 | */ 9 | create(): Promise 10 | 11 | /** 12 | * Execute update for record and model. 13 | */ 14 | update(): Promise 15 | 16 | /** 17 | * Execute hard delete for record and model. 18 | */ 19 | hardDelete(): Promise 20 | 21 | /** 22 | * Execute soft delete for record and model. 23 | */ 24 | softDelete(): Promise 25 | 26 | /** 27 | * Execute restore from soft delete for record and model. 28 | */ 29 | restore(): Promise 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/definitions/features/ITimestampsFeature.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.Feature { 5 | export interface ITimestampsSetting { 6 | createdAt: string 7 | updatedAt: string 8 | } 9 | 10 | export interface ITimestampsFeature extends IFeature { 11 | /** 12 | * Determine the model is using timestamps or not. 13 | */ 14 | hasTimestamps(model: Model.IModel): boolean 15 | 16 | /** 17 | * Get timestamps setting. 18 | * 19 | * Note: It's returns default timestamps even the model is not using timestamps. 20 | */ 21 | getTimestampsSetting(model: Model.IModel): ITimestampsSetting 22 | 23 | /** 24 | * Update the model's update timestamp. 25 | */ 26 | touch(model: Model.IModel): void 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/definitions/model/IModelEvent.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Model { 4 | export interface IModelEvent extends Najs.Contracts.Event.AsyncEventEmitter { 5 | /** 6 | * Trigger the event with both global and local EventEmitter. 7 | * 8 | * Listener in local EventEmitter triggered with the same args, in Global EventEmitter automatically add the model 9 | * instance as the first argument. For example: 10 | * 11 | * model.fire('test', [1, 2]) 12 | * 13 | * then: 14 | * 15 | * local_listener(data) // data = [1, 2] 16 | * global_listener(model, data) // model triggered, data = [1, 2] 17 | * 18 | * @param {string} eventName event's name 19 | * @param {mixed} args arguments 20 | */ 21 | fire(eventName: string, args?: any): Promise 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/definitions/model/IModelSoftDeletes.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Model { 4 | export declare class IModelSoftDeletes { 5 | /** 6 | * Soft deletes setting 7 | */ 8 | protected softDeletes?: Feature.ISoftDeletesSetting | boolean 9 | } 10 | 11 | export interface IModelSoftDeletes { 12 | /** 13 | * Determine model is soft-deleted or not. 14 | */ 15 | trashed(): boolean 16 | 17 | /** 18 | * Delete the model even soft delete is enabled. 19 | */ 20 | forceDelete(): Promise 21 | 22 | /** 23 | * Restore the model, only applied for model which has soft delete setting is enabled. 24 | */ 25 | restore(): Promise 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/definitions/model/IModelTimestamps.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Model { 4 | export declare class IModelTimestamps { 5 | /** 6 | * Timestamps setting. 7 | */ 8 | protected timestamps?: Feature.ITimestampsSetting | boolean 9 | } 10 | 11 | export interface IModelTimestamps { 12 | /** 13 | * Update the model's update timestamp. 14 | */ 15 | touch(): this 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/definitions/query-builders/IConditionMatcher.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.QueryBuilder { 2 | export type GroupQueryConditionData = { 3 | bool: 'and' | 'or' 4 | queries: Array 5 | } 6 | 7 | export type SingleQueryConditionData = { 8 | bool: 'and' | 'or' 9 | field: string 10 | operator: QueryGrammar.Operator 11 | value: any 12 | } 13 | 14 | export interface IConditionMatcher { 15 | isMatch(record: T): boolean 16 | } 17 | 18 | export interface IConditionMatcherFactory { 19 | make(data: SingleQueryConditionData): IConditionMatcher 20 | 21 | transform(matcher: IConditionMatcher): any 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/definitions/query-builders/IConvention.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.QueryBuilder { 2 | export interface IConvention { 3 | /** 4 | * Format the given name 5 | * 6 | * @param {string} name 7 | */ 8 | formatFieldName(name: string): string 9 | 10 | /** 11 | * Get null value for given name 12 | * 13 | * @param {string} name 14 | */ 15 | getNullValueFor(name: string): any 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/definitions/query-builders/IQueryBuilder.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | 7 | namespace NajsEloquent.QueryBuilder { 8 | // export type OmittedResult = Pick) | (keyof K)>> 9 | // export type OmittedQueryBuilderResult = Pick>> 10 | 11 | export declare class IQueryBuilder { 12 | protected handler: Handler 13 | } 14 | 15 | export interface IQueryBuilder 16 | extends QueryGrammar.IQuery, 17 | QueryGrammar.IConditionQuery, 18 | QueryGrammar.IExecuteQuery, 19 | QueryGrammar.IAdvancedQuery, 20 | QueryGrammar.IRelationQuery {} 21 | 22 | export type QueryBuilderInternal = IQueryBuilder & { handler: NajsEloquent.QueryBuilder.IQueryBuilderHandler } 23 | } 24 | -------------------------------------------------------------------------------- /lib/definitions/query-builders/IQueryBuilderFactory.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | 6 | namespace NajsEloquent.QueryBuilder { 7 | export declare interface IQueryBuilderFactory extends Najs.Contracts.Autoload { 8 | /** 9 | * Make new query builder instance from a model. 10 | * 11 | * @param {Model} model 12 | */ 13 | make(model: Model.IModel): IQueryBuilder 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/definitions/query-builders/IQueryExecutor.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | namespace NajsEloquent.QueryBuilder { 5 | export interface IQueryExecutor extends Driver.IExecutor { 6 | /** 7 | * Execute query and return the records as a Collection. 8 | */ 9 | get(): Promise 10 | 11 | /** 12 | * Execute query and returns the first record. 13 | */ 14 | first(): Promise 15 | 16 | /** 17 | * Execute query and returns count of records. 18 | */ 19 | count(): Promise 20 | 21 | /** 22 | * Update records which match the query with data. 23 | * 24 | * @param {Object} data 25 | */ 26 | update(data: Object): Promise 27 | 28 | /** 29 | * Delete all records which match the query. 30 | */ 31 | delete(): Promise 32 | 33 | /** 34 | * Restore all records which match the query. 35 | */ 36 | restore(): Promise 37 | 38 | /** 39 | * Execute query and returns raw result. 40 | */ 41 | execute(): Promise 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/definitions/query-grammars/IBasicQuery.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.QueryGrammar { 2 | export interface IBasicQuery { 3 | /** 4 | * Set the columns or fields to be selected. 5 | * 6 | * @param {string|string[]} fields 7 | */ 8 | select(...fields: Array): this 9 | 10 | /** 11 | * Set the "limit" value of the query. 12 | * @param {number} records 13 | */ 14 | limit(record: number): this 15 | 16 | /** 17 | * Add an "order by" clause to the query. 18 | * 19 | * @param {string} field 20 | */ 21 | orderBy(field: string): this 22 | /** 23 | * Add an "order by" clause to the query. 24 | * 25 | * @param {string} field 26 | * @param {string} direction 27 | */ 28 | orderBy(field: string, direction: 'asc' | 'desc'): this 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/definitions/query-grammars/IExecuteQuery.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.QueryGrammar { 4 | export interface IExecuteQuery { 5 | /** 6 | * Execute query and returns count of records. 7 | */ 8 | count(): Promise 9 | 10 | /** 11 | * Update records which match the query with data. 12 | * 13 | * @param {Object} data 14 | */ 15 | update(data: Object): Promise 16 | 17 | /** 18 | * Delete all records which match the query. 19 | */ 20 | delete(): Promise 21 | 22 | /** 23 | * Restore all records which match the query. 24 | */ 25 | restore(): Promise 26 | 27 | /** 28 | * Execute query and returns raw result. 29 | */ 30 | execute(): Promise 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/definitions/query-grammars/IQuery.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.QueryGrammar { 4 | export interface IQuery extends IBasicQuery { 5 | /** 6 | * Set the query with given name 7 | * 8 | * @param {string} name 9 | */ 10 | queryName(name: string): this 11 | 12 | /** 13 | * Set the query log group name 14 | * 15 | * @param {string} group QueryLog group 16 | */ 17 | setLogGroup(group: string): this 18 | 19 | /** 20 | * Add an "order by" clause to the query with direction ASC. 21 | * 22 | * @param {string} field 23 | * @param {string} direction 24 | */ 25 | orderByAsc(field: string): this 26 | 27 | /** 28 | * Add an "order by" clause to the query with direction DESC. 29 | * 30 | * @param {string} field 31 | * @param {string} direction 32 | */ 33 | orderByDesc(field: string): this 34 | 35 | /** 36 | * Consider all soft-deleted or not-deleted items. 37 | */ 38 | withTrashed(): this 39 | 40 | /** 41 | * Consider soft-deleted items only. 42 | */ 43 | onlyTrashed(): this 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/definitions/query-grammars/IRelationQuery.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.QueryGrammar { 2 | export interface IRelationQuery { 3 | /** 4 | * Load given relations name when the query get executed. 5 | * 6 | * @param {string|string[]} relations 7 | */ 8 | with(...relations: Array): this 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/definitions/relations/IBelongsToRelationship.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Relation { 2 | export interface IBelongsToRelationship extends IRelationship { 3 | dissociate(): void 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lib/definitions/relations/IHasManyRelationship.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Relation { 4 | export interface IHasManyRelationship extends IRelationship> { 5 | associate(...models: Array>): this 6 | 7 | dissociate(...models: Array>): this 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lib/definitions/relations/IHasOneRelationship.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Relation { 2 | export interface IHasOneRelationship extends IRelationship { 3 | associate(model: T): void 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lib/definitions/relations/IMorphManyRelationship.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Relation { 4 | export interface IMorphManyRelationship extends IRelationship> { 5 | associate(...models: Array>): this 6 | 7 | dissociate(...models: Array>): this 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lib/definitions/relations/IMorphOneRelationship.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Relation { 2 | export interface IMorphOneRelationship extends IRelationship { 3 | associate(model: T): void 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lib/definitions/relations/IMorphToRelationship.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Relation { 2 | export interface IMorphToRelationship extends IRelationship {} 3 | } 4 | -------------------------------------------------------------------------------- /lib/definitions/relations/IPivotOptions.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Relation { 2 | export type PivotForeignKey = string 3 | 4 | export interface IPivotOptions { 5 | foreignKeys: [PivotForeignKey, PivotForeignKey] 6 | 7 | name?: string 8 | 9 | fields?: Array 10 | 11 | timestamps?: Feature.ITimestampsSetting 12 | 13 | softDeletes?: Feature.ISoftDeletesSetting 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/definitions/relations/IRelationData.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace NajsEloquent.Relation { 4 | export interface IRelationData { 5 | getFactory(): IRelationshipFactory 6 | 7 | isLoaded(): boolean 8 | 9 | hasData(): boolean 10 | 11 | getData(): T | undefined | null 12 | 13 | setData(data: T | undefined | null): T | undefined | null 14 | 15 | getLoadType(): 'unknown' | 'lazy' | 'eager' 16 | 17 | setLoadType(type: 'lazy' | 'eager'): this 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/definitions/utils/IClassSetting.ts: -------------------------------------------------------------------------------- 1 | namespace NajsEloquent.Util { 2 | export interface ISettingReader { 3 | (staticValue?: T, sampleValue?: T, instanceValue?: T): T 4 | } 5 | 6 | export interface IClassSetting { 7 | /** 8 | * Read property setting via a setting reader. 9 | * 10 | * @param {string} property 11 | * @param {Function} reader 12 | */ 13 | read(property: string, reader: ISettingReader): T 14 | 15 | /** 16 | * Get the "sample" instance. 17 | */ 18 | getSample(): T 19 | 20 | /** 21 | * Get definition of the class. 22 | */ 23 | getDefinition(): Function 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/drivers/ExecutorBase.ts: -------------------------------------------------------------------------------- 1 | export class ExecutorBase { 2 | private executeMode: string = 'default' 3 | 4 | setExecuteMode(mode: 'default' | 'disabled'): this { 5 | this.executeMode = mode 6 | 7 | return this 8 | } 9 | 10 | shouldExecute(): boolean { 11 | return this.executeMode !== 'disabled' 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/drivers/Record.ts: -------------------------------------------------------------------------------- 1 | import { get, set, isEqual } from 'lodash' 2 | 3 | export class Record { 4 | protected data: object 5 | protected modified: string[] 6 | 7 | constructor(data?: object | Record) { 8 | if (data instanceof Record) { 9 | this.data = data!.data 10 | } else { 11 | this.data = data || {} 12 | } 13 | this.modified = [] 14 | } 15 | 16 | getAttribute(path: string): T { 17 | return get(this.data, path) 18 | } 19 | 20 | setAttribute(path: string, value: T): boolean { 21 | const originalValue = get(this.data, path) 22 | 23 | if (!isEqual(originalValue, value)) { 24 | set(this.data, path, value) 25 | this.markModified(path) 26 | } 27 | 28 | return true 29 | } 30 | 31 | clearModified(): this { 32 | this.modified = [] 33 | 34 | return this 35 | } 36 | 37 | getModified(): string[] { 38 | return this.modified 39 | } 40 | 41 | markModified(name: string): void { 42 | if (this.modified.indexOf(name) === -1) { 43 | this.modified.push(name) 44 | } 45 | } 46 | 47 | toObject(): object { 48 | return this.data 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/drivers/RecordConditionMatcher.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import IConditionMatcher = NajsEloquent.QueryBuilder.IConditionMatcher 4 | 5 | import { Record } from './Record' 6 | import { DataConditionMatcher } from '../data/DataConditionMatcher' 7 | import { RecordDataReader } from './RecordDataReader' 8 | 9 | export class RecordConditionMatcher extends DataConditionMatcher implements IConditionMatcher { 10 | constructor(field: string, operator: string, value: any) { 11 | super(field, operator, value, RecordDataReader) 12 | } 13 | 14 | toJSON(): object { 15 | return { 16 | field: this.field, 17 | operator: this.operator, 18 | value: this.value 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/drivers/RecordConditionMatcherFactory.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import IConditionMatcherFactory = NajsEloquent.QueryBuilder.IConditionMatcherFactory 4 | import SingleQueryConditionData = NajsEloquent.QueryBuilder.SingleQueryConditionData 5 | 6 | import { register } from 'najs-binding' 7 | import { RecordConditionMatcher } from './RecordConditionMatcher' 8 | import { NajsEloquent as NajsEloquentClasses } from '../constants' 9 | 10 | export class RecordConditionMatcherFactory implements IConditionMatcherFactory { 11 | static className: string = NajsEloquentClasses.Driver.Memory.RecordConditionMatcherFactory 12 | 13 | getClassName() { 14 | return NajsEloquentClasses.Driver.Memory.RecordConditionMatcherFactory 15 | } 16 | 17 | make(data: SingleQueryConditionData): RecordConditionMatcher { 18 | return new RecordConditionMatcher(data.field, data.operator, data.value) 19 | } 20 | 21 | transform(matcher: RecordConditionMatcher): RecordConditionMatcher { 22 | return matcher 23 | } 24 | } 25 | register(RecordConditionMatcherFactory, NajsEloquentClasses.Driver.Memory.RecordConditionMatcherFactory, true, true) 26 | -------------------------------------------------------------------------------- /lib/drivers/RecordDataReader.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { pick } from 'lodash' 4 | import { Record } from './Record' 5 | import { isObjectId } from '../util/helpers' 6 | 7 | export const RecordDataReader: NajsEloquent.Data.IDataReader = { 8 | getAttribute(data: Record, field: string) { 9 | return this.toComparable(data.getAttribute(field)) 10 | }, 11 | 12 | pick(record: Record, selectedFields: string[]): Record { 13 | const data = record.toObject() 14 | 15 | return new Record(pick(data, selectedFields)) 16 | }, 17 | 18 | toComparable(value: any) { 19 | return isObjectId(value) ? (value as any).toHexString() : value 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/drivers/RecordDataSourceBase.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import { Record } from './Record' 5 | import { RecordDataReader } from './RecordDataReader' 6 | import { DataBuffer } from '../data/DataBuffer' 7 | 8 | export abstract class RecordDataSourceBase extends DataBuffer 9 | implements Najs.Contracts.Eloquent.MemoryDataSource { 10 | protected modelName: string 11 | 12 | constructor(model: NajsEloquent.Model.IModel) { 13 | super(model.getPrimaryKeyName(), RecordDataReader) 14 | this.modelName = model.getModelName() 15 | } 16 | 17 | getModelName(): string { 18 | return this.modelName 19 | } 20 | 21 | abstract getClassName(): string 22 | abstract createPrimaryKeyIfNeeded(data: Record): string 23 | abstract read(): Promise 24 | abstract write(): Promise 25 | 26 | add(data: Record): this { 27 | this.createPrimaryKeyIfNeeded(data) 28 | 29 | return super.add(data) 30 | } 31 | 32 | remove(data: Record): this { 33 | this.createPrimaryKeyIfNeeded(data) 34 | 35 | return super.remove(data) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/drivers/memory/MemoryDataSource.ts: -------------------------------------------------------------------------------- 1 | import { register } from 'najs-binding' 2 | import { ObjectId } from 'bson' 3 | import { NajsEloquent as NajsEloquentClasses } from '../../constants' 4 | import { Record } from '../Record' 5 | import { RecordDataSourceBase } from '../RecordDataSourceBase' 6 | 7 | export class MemoryDataSource extends RecordDataSourceBase { 8 | static className: string = NajsEloquentClasses.Driver.Memory.MemoryDataSource 9 | 10 | getClassName(): string { 11 | return NajsEloquentClasses.Driver.Memory.MemoryDataSource 12 | } 13 | 14 | createPrimaryKeyIfNeeded(data: Record): string { 15 | const primaryKey = data.getAttribute(this.primaryKeyName) 16 | if (primaryKey) { 17 | return primaryKey 18 | } 19 | 20 | const newId = new ObjectId().toHexString() 21 | data.setAttribute(this.primaryKeyName, newId) 22 | 23 | return newId 24 | } 25 | 26 | async read(): Promise { 27 | return true 28 | } 29 | 30 | async write(): Promise { 31 | return true 32 | } 33 | } 34 | register(MemoryDataSource, NajsEloquentClasses.Driver.Memory.MemoryDataSource) 35 | -------------------------------------------------------------------------------- /lib/drivers/memory/MemoryQueryBuilder.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import IModel = NajsEloquent.Model.IModel 4 | import { QueryBuilder } from '../../query-builders/QueryBuilder' 5 | import { MemoryQueryBuilderHandler } from './MemoryQueryBuilderHandler' 6 | 7 | export class MemoryQueryBuilder< 8 | T extends IModel, 9 | H extends MemoryQueryBuilderHandler = MemoryQueryBuilderHandler 10 | > extends QueryBuilder {} 11 | -------------------------------------------------------------------------------- /lib/drivers/memory/MemoryQueryBuilderFactory.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | import { register } from 'najs-binding' 6 | import { NajsEloquent as NajsEloquentClasses } from '../../constants' 7 | import { MemoryQueryBuilder } from './MemoryQueryBuilder' 8 | import { MemoryQueryBuilderHandler } from './MemoryQueryBuilderHandler' 9 | 10 | export class MemoryQueryBuilderFactory implements NajsEloquent.QueryBuilder.IQueryBuilderFactory { 11 | static className: string = NajsEloquentClasses.Driver.Memory.MemoryQueryBuilderFactory 12 | 13 | getClassName() { 14 | return NajsEloquentClasses.Driver.Memory.MemoryQueryBuilderFactory 15 | } 16 | 17 | make(model: NajsEloquent.Model.IModel): MemoryQueryBuilder { 18 | return new MemoryQueryBuilder(new MemoryQueryBuilderHandler(model)) 19 | } 20 | } 21 | register(MemoryQueryBuilderFactory, NajsEloquentClasses.Driver.Memory.MemoryQueryBuilderFactory, true, true) 22 | -------------------------------------------------------------------------------- /lib/drivers/memory/MemoryQueryLog.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import MemoryDataSource = Najs.Contracts.Eloquent.MemoryDataSource 3 | import { Record } from '../Record' 4 | import { QueryLogBase, IQueryLogData } from '../QueryLogBase' 5 | 6 | export interface IMemoryLogData extends IQueryLogData { 7 | dataSource?: string 8 | records?: IUpdateRecordInfo[] 9 | } 10 | export interface IUpdateRecordInfo { 11 | origin: object 12 | modified: boolean 13 | updated: object 14 | } 15 | 16 | export class MemoryQueryLog extends QueryLogBase { 17 | getDefaultData(): IMemoryLogData { 18 | return this.getEmptyData() 19 | } 20 | 21 | dataSource(ds: MemoryDataSource): this { 22 | this.data.dataSource = ds.getClassName() 23 | 24 | return this 25 | } 26 | 27 | updateRecordInfo(info: IUpdateRecordInfo): this { 28 | if (typeof this.data.records === 'undefined') { 29 | this.data.records = [] 30 | } 31 | this.data.records.push(info) 32 | 33 | return this 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/errors/NotFoundError.ts: -------------------------------------------------------------------------------- 1 | const MESSAGE = ':model is not found.' 2 | 3 | export class NotFoundError extends Error { 4 | static className: string = 'NotFoundError' 5 | 6 | model: string 7 | 8 | constructor(model: string) { 9 | super(MESSAGE.replace(':model', model)) 10 | Error.captureStackTrace(this, NotFoundError) 11 | this.name = NotFoundError.className 12 | this.model = model 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/errors/RelationNotDefinedError.ts: -------------------------------------------------------------------------------- 1 | const MESSAGE = 'Relation :name is not defined in model :model.' 2 | 3 | export class RelationNotDefinedError extends Error { 4 | static className: string = 'NotFoundError' 5 | 6 | relationName: string 7 | model: string 8 | 9 | constructor(name: string, model: string) { 10 | super(MESSAGE.replace(':name', name).replace(':model', model)) 11 | Error.captureStackTrace(this, RelationNotDefinedError) 12 | this.name = RelationNotDefinedError.className 13 | this.relationName = name 14 | this.model = model 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/errors/RelationNotFoundInNewInstanceError.ts: -------------------------------------------------------------------------------- 1 | const MESSAGE = 'Cannot load relation :name in a new instance of :model.' 2 | 3 | export class RelationNotFoundInNewInstanceError extends Error { 4 | static className: string = 'RelationNotFoundInNewInstanceError' 5 | 6 | relationName: string 7 | model: string 8 | 9 | constructor(name: string, model: string) { 10 | super(MESSAGE.replace(':name', name).replace(':model', model)) 11 | Error.captureStackTrace(this, RelationNotFoundInNewInstanceError) 12 | this.name = RelationNotFoundInNewInstanceError.className 13 | this.relationName = name 14 | this.model = model 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/facades/container.ts: -------------------------------------------------------------------------------- 1 | declare const global: object 2 | 3 | import { FacadeContainer, IFacadeContainer } from 'najs-facade' 4 | 5 | class NajsEloquentBag extends FacadeContainer {} 6 | 7 | export const container: IFacadeContainer = new NajsEloquentBag() 8 | global['NajsEloquent'] = container 9 | -------------------------------------------------------------------------------- /lib/facades/global/DriverProviderFacade.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import '../../providers/DriverProvider' 4 | import { make } from 'najs-binding' 5 | import { Facade, IFacade, IFacadeBase } from 'najs-facade' 6 | import { container } from '../container' 7 | import { NajsEloquent } from '../../constants' 8 | 9 | const facade = Facade.create(container, 'DriverProvider', function() { 10 | return make(NajsEloquent.Provider.DriverProvider) 11 | }) 12 | 13 | export const DriverProviderFacade: Najs.Contracts.Eloquent.DriverProvider & IFacade = facade 14 | export const DriverProvider: Najs.Contracts.Eloquent.DriverProvider & IFacadeBase = facade 15 | -------------------------------------------------------------------------------- /lib/facades/global/MemoryDataSourceProviderFacade.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import '../../providers/MemoryDataSourceProvider' 4 | import { Record } from '../../drivers/Record' 5 | import { MemoryDataSourceProvider as MemoryDataSourceProviderClass } from '../../providers/MemoryDataSourceProvider' 6 | import { make } from 'najs-binding' 7 | import { Facade, IFacade, IFacadeBase } from 'najs-facade' 8 | import { container } from '../container' 9 | import { NajsEloquent } from '../../constants' 10 | 11 | const facade = Facade.create(container, 'MemoryDataSourceProvider', function() { 12 | return make(NajsEloquent.Provider.MemoryDataSourceProvider) 13 | }) 14 | 15 | export const MemoryDataSourceProviderFacade: Najs.Contracts.Eloquent.MemoryDataSourceProvider & IFacade = facade 16 | export const MemoryDataSourceProvider: Najs.Contracts.Eloquent.MemoryDataSourceProvider & IFacadeBase = facade 17 | -------------------------------------------------------------------------------- /lib/facades/global/MomentProviderFacade.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import '../../providers/MomentProvider' 4 | import { make } from 'najs-binding' 5 | import { MomentProvider as MomentProviderClass } from '../../providers/MomentProvider' 6 | import { Facade, IFacade, IFacadeBase } from 'najs-facade' 7 | import { Moment } from 'moment' 8 | import { container } from '../container' 9 | import { NajsEloquent } from '../../constants' 10 | 11 | const facade = Facade.create(container, 'MomentProvider', function() { 12 | return make(NajsEloquent.Provider.MomentProvider) 13 | }) 14 | 15 | export const MomentProviderFacade: Najs.Contracts.Eloquent.MomentProvider & IFacade = facade 16 | export const MomentProvider: Najs.Contracts.Eloquent.MomentProvider & IFacadeBase = facade 17 | -------------------------------------------------------------------------------- /lib/facades/global/QueryLogFacade.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import '../../query-log/FlipFlopQueryLog' 4 | import { make } from 'najs-binding' 5 | import { Facade, IFacade, IFacadeBase } from 'najs-facade' 6 | import { container } from '../container' 7 | import { NajsEloquent } from '../../constants' 8 | 9 | const facade = Facade.create(container, 'QueryLog', function() { 10 | return make(NajsEloquent.QueryLog.FlipFlopQueryLog) 11 | }) 12 | 13 | export const QueryLogFacade: Najs.Contracts.Eloquent.QueryLog & IFacade = facade 14 | export const QueryLog: Najs.Contracts.Eloquent.QueryLog & IFacadeBase = facade 15 | -------------------------------------------------------------------------------- /lib/features/mixin/SoftDeletesPublicApi.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import Model = NajsEloquent.Model.ModelInternal 4 | 5 | export const SoftDeletesPublicApi: NajsEloquent.Model.IModelSoftDeletes = { 6 | trashed(this: Model): boolean { 7 | return this.driver.getSoftDeletesFeature().trashed(this) 8 | }, 9 | 10 | forceDelete(this: Model): Promise { 11 | return this.driver.getSoftDeletesFeature().forceDelete(this) 12 | }, 13 | 14 | restore(this: Model): Promise { 15 | return this.driver.getSoftDeletesFeature().restore(this) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/features/mixin/TimestampsPublicApi.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import Model = NajsEloquent.Model.ModelInternal 4 | 5 | export const TimestampsPublicApi: NajsEloquent.Model.IModelTimestamps = { 6 | touch(this: Model) { 7 | this.driver.getTimestampsFeature().touch(this) 8 | 9 | return this 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/model/ModelEvent.ts: -------------------------------------------------------------------------------- 1 | export enum ModelEvent { 2 | Creating = 'creating', 3 | Created = 'created', 4 | Saving = 'saving', 5 | Saved = 'saved', 6 | Updating = 'updating', 7 | Updated = 'updated', 8 | Deleting = 'deleting', 9 | Deleted = 'deleted', 10 | Restoring = 'restoring', 11 | Restored = 'restored' 12 | } 13 | -------------------------------------------------------------------------------- /lib/model/ModelProxyHandler.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import Model = NajsEloquent.Model.ModelInternal 4 | 5 | export const ModelProxyHandler: ProxyHandler = { 6 | get(target: Model, key: string) { 7 | if (target.driver.shouldBeProxied(target, key)) { 8 | return target.driver.proxify('get', target, key) 9 | } 10 | return target[key] 11 | }, 12 | 13 | set(target: Model, key: string, value: any): boolean { 14 | if (target.driver.shouldBeProxied(target, key)) { 15 | return target.driver.proxify('set', target, key, value) 16 | } 17 | target[key] = value 18 | return true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/providers/MomentProvider.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { Moment } from 'moment' 4 | import { register } from 'najs-binding' 5 | import { Facade } from 'najs-facade' 6 | import { NajsEloquent } from '../constants' 7 | 8 | const moment = require('moment') 9 | 10 | export class MomentProvider extends Facade implements Najs.Contracts.Eloquent.MomentProvider { 11 | getClassName() { 12 | return NajsEloquent.Provider.MomentProvider 13 | } 14 | 15 | make(): Moment { 16 | return moment(...arguments) 17 | } 18 | 19 | isMoment(value: any): boolean { 20 | return moment.isMoment(value) 21 | } 22 | 23 | setNow(cb: () => any): this { 24 | moment.now = cb 25 | 26 | return this 27 | } 28 | } 29 | register(MomentProvider, NajsEloquent.Provider.MomentProvider) 30 | -------------------------------------------------------------------------------- /lib/query-builders/QueryBuilder.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | // import IModel = NajsEloquent.Model.IModel 4 | import IQueryBuilder = NajsEloquent.QueryBuilder.IQueryBuilder 5 | 6 | import { Query } from './mixin/Query' 7 | import { ConditionQuery } from './mixin/ConditionQuery' 8 | import { ExecuteQuery } from './mixin/ExecuteQuery' 9 | import { AdvancedQuery } from './mixin/AdvancedQuery' 10 | import { RelationQuery } from './mixin/RelationQuery' 11 | import { QueryBuilderHandlerBase } from './QueryBuilderHandlerBase' 12 | 13 | export interface QueryBuilder 14 | extends IQueryBuilder {} 15 | export class QueryBuilder { 16 | protected handler: H 17 | 18 | constructor(handler: H) { 19 | this.handler = handler 20 | } 21 | } 22 | Object.assign(QueryBuilder.prototype, Query, ConditionQuery, ExecuteQuery, AdvancedQuery, RelationQuery) 23 | -------------------------------------------------------------------------------- /lib/query-builders/mixin/ExecuteQuery.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import QueryBuilder = NajsEloquent.QueryBuilder.QueryBuilderInternal 5 | 6 | export const ExecuteQuery: NajsEloquent.QueryGrammar.IExecuteQuery = { 7 | async count(this: QueryBuilder): Promise { 8 | return this.handler.getQueryExecutor().count() 9 | }, 10 | 11 | async update(this: QueryBuilder, data: Object): Promise { 12 | return this.handler.getQueryExecutor().update(this) 13 | }, 14 | 15 | async delete(this: QueryBuilder): Promise { 16 | return this.handler.getQueryExecutor().delete() 17 | }, 18 | 19 | async restore(this: QueryBuilder): Promise { 20 | return this.handler.getQueryExecutor().restore() 21 | }, 22 | 23 | async execute(this: QueryBuilder): Promise { 24 | return this.handler.getQueryExecutor().execute() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/query-builders/mixin/RelationQuery.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import QueryBuilder = NajsEloquent.QueryBuilder.QueryBuilderInternal 3 | 4 | import { flatten } from 'lodash' 5 | 6 | export const RelationQuery: NajsEloquent.QueryGrammar.IRelationQuery = { 7 | with(this: QueryBuilder, ...relations: Array) { 8 | this.handler.setEagerRelations(flatten(relations)) 9 | 10 | return this 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/query-builders/shared/DefaultConvention.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | export class DefaultConvention implements NajsEloquent.QueryBuilder.IConvention { 4 | formatFieldName(name: any) { 5 | return name 6 | } 7 | 8 | getNullValueFor(name: any) { 9 | // tslint:disable-next-line 10 | return null 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/query-builders/shared/ExecutorUtils.ts: -------------------------------------------------------------------------------- 1 | import { QueryBuilderHandlerBase } from '../QueryBuilderHandlerBase' 2 | 3 | export class ExecutorUtils { 4 | static addSoftDeleteConditionIfNeeded(handler: QueryBuilderHandlerBase) { 5 | if (handler.shouldAddSoftDeleteCondition()) { 6 | const settings = handler.getSoftDeletesSetting() 7 | handler.getConditionQuery().whereNull(settings.deletedAt) 8 | handler.markSoftDeleteState('added') 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/query-builders/shared/Operator.ts: -------------------------------------------------------------------------------- 1 | export enum Operator { 2 | And = 'and', 3 | Or = 'or', 4 | GreaterThan = '>', 5 | LessThan = '<', 6 | Equals = '=', 7 | NotEquals = '<>', 8 | GreaterThanOrEquals = '>=', 9 | LessThanOrEquals = '<=', 10 | In = 'in', 11 | NotIn = 'not-in' 12 | } 13 | -------------------------------------------------------------------------------- /lib/relations/RelationshipType.ts: -------------------------------------------------------------------------------- 1 | export enum RelationshipType { 2 | HasOne = 'HasOne', 3 | HasMany = 'HasMany', 4 | BelongsTo = 'BelongsTo', 5 | BelongsToMany = 'BelongsToMany', 6 | MorphOne = 'MorphOne', 7 | MorphMany = 'MorphMany', 8 | MorphTo = 'MorphTo' 9 | } 10 | -------------------------------------------------------------------------------- /lib/relations/relationships/executors/HasOneExecutor.ts: -------------------------------------------------------------------------------- 1 | import { HasOneOrManyExecutor } from './HasOneOrManyExecutor' 2 | 3 | export class HasOneExecutor extends HasOneOrManyExecutor { 4 | async executeQuery(): Promise { 5 | return this.query.first() as any 6 | } 7 | 8 | executeCollector(): T | undefined | null { 9 | this.collector.limit(1) 10 | const result = this.collector.exec() 11 | if (result.length === 0) { 12 | return undefined 13 | } 14 | return this.dataBucket.makeModel(this.targetModel, result[0]) as any 15 | } 16 | 17 | getEmptyValue(): T | undefined { 18 | return undefined 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/util/PrototypeManager.ts: -------------------------------------------------------------------------------- 1 | export const PrototypeManager = { 2 | stopFindingRelationsPrototypes: [Object.prototype], 3 | 4 | stopFindingRelationsIn(prototype: object) { 5 | if (this.shouldFindRelationsIn(prototype)) { 6 | this.stopFindingRelationsPrototypes.push(prototype) 7 | } 8 | }, 9 | 10 | shouldFindRelationsIn(prototype: object): boolean { 11 | for (const item of this.stopFindingRelationsPrototypes) { 12 | if (item === prototype) { 13 | return false 14 | } 15 | } 16 | return true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/util/SettingType.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { array_unique } from './functions' 4 | 5 | export class SettingType { 6 | static arrayUnique(initializeValue: T[], defaultValue: T[]): NajsEloquent.Util.ISettingReader { 7 | return function(staticValue?: T[], sampleValue?: T[], instanceValue?: T[]): T[] { 8 | if (!staticValue && !sampleValue && !instanceValue) { 9 | return defaultValue 10 | } 11 | 12 | const values: T[] = initializeValue 13 | .concat(staticValue ? staticValue : []) 14 | .concat(sampleValue ? sampleValue : []) 15 | .concat(instanceValue ? instanceValue : []) 16 | 17 | const result = array_unique(values) 18 | if (result.length === 0) { 19 | return defaultValue 20 | } 21 | return result 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/util/accessors.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | export function relationFeatureOf(model: NajsEloquent.Model.IModel) { 4 | return model.getDriver().getRelationFeature() 5 | } 6 | -------------------------------------------------------------------------------- /lib/util/factory.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | const collect = require('collect.js') 4 | 5 | export function make_collection(data: object): CollectJs.Collection 6 | export function make_collection(data: T[]): CollectJs.Collection 7 | export function make_collection(data: T[], converter: (item: T) => R): CollectJs.Collection 8 | export function make_collection(data: T[], converter?: (item: T) => R): CollectJs.Collection { 9 | if (typeof converter === 'undefined') { 10 | return collect(data) 11 | } 12 | return collect(data.map(converter)) 13 | } 14 | -------------------------------------------------------------------------------- /lib/util/isPromise.ts: -------------------------------------------------------------------------------- 1 | export function isPromise(obj: any) { 2 | return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function' 3 | } 4 | -------------------------------------------------------------------------------- /najs-eloquent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/najs-framework/najs-eloquent/99a322f2cb3c068ef0b64fe1109f2e16d421a944/najs-eloquent.png -------------------------------------------------------------------------------- /test/_integration/model/ModelEvent.integration.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { Model } from '../../../lib' 3 | 4 | class User extends Model { 5 | getClassName() { 6 | return 'ModelEvent.User' 7 | } 8 | } 9 | Model.register(User) 10 | 11 | class Post extends Model { 12 | getClassName() { 13 | return 'ModelEvent.Post' 14 | } 15 | } 16 | Model.register(Post) 17 | 18 | describe('Model Event integration test', function() { 19 | it('should work with global event listener', async function() { 20 | const user = new User() 21 | const post = new Post() 22 | 23 | User.on('created', async function(createdModel: any) { 24 | if (createdModel instanceof User) { 25 | expect(createdModel === user).toBe(true) 26 | } else { 27 | expect(createdModel === post).toBe(true) 28 | } 29 | }) 30 | 31 | // Post.once('created', async function(createdModel: any) { 32 | // console.log(arguments) 33 | // if (createdModel instanceof User) { 34 | // expect(createdModel === user).toBe(true) 35 | // } else { 36 | // expect(createdModel === post).toBe(true) 37 | // } 38 | // }) 39 | 40 | await user.save() 41 | await post.save() 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /test/drivers/ExecutorBase.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { ExecutorBase } from '../../lib/drivers/ExecutorBase' 3 | 4 | describe('ExecutorBase', function() { 5 | describe('.setExecuteMode()', function() { 6 | it('is chainable, can set executeMode to default or disabled', function() { 7 | const executor = new ExecutorBase() 8 | expect(executor.setExecuteMode('default') === executor).toBe(true) 9 | expect(executor.shouldExecute()).toBe(true) 10 | expect(executor.setExecuteMode('disabled') === executor).toBe(true) 11 | expect(executor.shouldExecute()).toBe(false) 12 | }) 13 | }) 14 | 15 | describe('.shouldExecute()', function() { 16 | it('returns false if executeMode is disabled', function() { 17 | const executor = new ExecutorBase() 18 | expect(executor.setExecuteMode('default') === executor).toBe(true) 19 | expect(executor.shouldExecute()).toBe(true) 20 | expect(executor.setExecuteMode('disabled') === executor).toBe(true) 21 | expect(executor.shouldExecute()).toBe(false) 22 | }) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /test/drivers/memory/MemoryQueryBuilder.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { QueryBuilder } from '../../../lib/query-builders/QueryBuilder' 3 | import { MemoryQueryBuilder } from '../../../lib/drivers/memory/MemoryQueryBuilder' 4 | import { MemoryQueryBuilderHandler } from '../../../lib/drivers/memory/MemoryQueryBuilderHandler' 5 | import { MemoryDataSource } from '../../../lib/drivers/memory/MemoryDataSource' 6 | import { MemoryDataSourceProvider } from '../../../lib/facades/global/MemoryDataSourceProviderFacade' 7 | 8 | MemoryDataSourceProvider.register(MemoryDataSource, 'memory', true) 9 | 10 | describe('MemoryQueryBuilder', function() { 11 | it('extends QueryBuilder', function() { 12 | const model: any = {} 13 | const instance = new MemoryQueryBuilder(new MemoryQueryBuilderHandler(model)) 14 | expect(instance).toBeInstanceOf(QueryBuilder) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /test/facades/container.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { FacadeContainer } from 'najs-facade' 3 | import { container } from '../../lib/facades/container' 4 | 5 | describe('Najs Facade Container', function() { 6 | it('is an instance of FacadeContainer, it has global reference called "NajsEloquent"', function() { 7 | expect(container).toBeInstanceOf(FacadeContainer) 8 | expect(global['NajsEloquent'] === container).toBe(true) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /test/facades/global/EloquentDriverProviderFacade.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import '../../../lib/providers/DriverProvider' 3 | import * as NajsBinding from 'najs-binding' 4 | import * as Sinon from 'sinon' 5 | import { NajsEloquent } from '../../../lib/constants' 6 | import { DriverProviderFacade } from '../../../lib/facades/global/DriverProviderFacade' 7 | 8 | describe('DriverProviderFacade', function() { 9 | it('calls make() to create new instance of DriverProvider as a facade root', function() { 10 | const makeSpy = Sinon.spy(NajsBinding, 'make') 11 | DriverProviderFacade.reloadFacadeRoot() 12 | expect(makeSpy.calledWith(NajsEloquent.Provider.DriverProvider)).toBe(true) 13 | expect(makeSpy.calledOnce).toBe(true) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /test/facades/global/MemoryDataSourceProviderFacade.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import '../../../lib/drivers/memory/MemoryDataSource' 3 | import * as NajsBinding from 'najs-binding' 4 | import * as Sinon from 'sinon' 5 | import { NajsEloquent } from '../../../lib/constants' 6 | import { MemoryDataSourceProviderFacade } from '../../../lib/facades/global/MemoryDataSourceProviderFacade' 7 | 8 | describe('MemoryDataSourceProviderFacade', function() { 9 | it('calls make() to create new instance of MemoryDataSourceFacade as a facade root', function() { 10 | const makeSpy = Sinon.spy(NajsBinding, 'make') 11 | MemoryDataSourceProviderFacade.reloadFacadeRoot() 12 | expect(makeSpy.calledWith(NajsEloquent.Provider.MemoryDataSourceProvider)).toBe(true) 13 | expect(makeSpy.calledOnce).toBe(true) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /test/facades/global/MomentProviderFacade.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import '../../../lib/providers/MomentProvider' 3 | import * as NajsBinding from 'najs-binding' 4 | import * as Sinon from 'sinon' 5 | import { NajsEloquent } from '../../../lib/constants' 6 | import { MomentProviderFacade } from '../../../lib/facades/global/MomentProviderFacade' 7 | 8 | describe('MomentProviderFacade', function() { 9 | it('calls make() to create new instance of MomentFacade as a facade root', function() { 10 | const makeSpy = Sinon.spy(NajsBinding, 'make') 11 | MomentProviderFacade.reloadFacadeRoot() 12 | expect(makeSpy.calledWith(NajsEloquent.Provider.MomentProvider)).toBe(true) 13 | expect(makeSpy.calledOnce).toBe(true) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /test/facades/global/QueryLogFacade.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import '../../../lib/query-log/FlipFlopQueryLog' 3 | import * as NajsBinding from 'najs-binding' 4 | import * as Sinon from 'sinon' 5 | import { NajsEloquent } from '../../../lib/constants' 6 | import { QueryLogFacade } from '../../../lib/facades/global/QueryLogFacade' 7 | 8 | describe('QueryLogFacade', function() { 9 | it('calls make() to create new instance of FlipFlopQueryLog as a facade root', function() { 10 | const makeSpy = Sinon.spy(NajsBinding, 'make') 11 | QueryLogFacade.reloadFacadeRoot() 12 | expect(makeSpy.calledWith(NajsEloquent.QueryLog.FlipFlopQueryLog)).toBe(true) 13 | expect(makeSpy.calledOnce).toBe(true) 14 | }) 15 | }) 16 | -------------------------------------------------------------------------------- /test/features/mixin/TimestampsPublicApi.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import * as Sinon from 'sinon' 3 | import { TimestampsPublicApi } from '../../../lib/features/mixin/TimestampsPublicApi' 4 | 5 | describe('TimestampsPublicApi', function() { 6 | const timestampsFeature = { 7 | touch() { 8 | return 'touch-result' 9 | } 10 | } 11 | 12 | const model = { 13 | driver: { 14 | getTimestampsFeature() { 15 | return timestampsFeature 16 | } 17 | } 18 | } 19 | 20 | describe('.touch()', function() { 21 | it('is chainable, calls TimestampsFeature.touch()', function() { 22 | const stub = Sinon.stub(timestampsFeature, 'touch') 23 | stub.returns('anything') 24 | 25 | expect(TimestampsPublicApi.touch.call(model) === model).toBe(true) 26 | expect(stub.calledWith(model)).toBe(true) 27 | stub.restore() 28 | }) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /test/query-builders/mixin/ExecuteQuery.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import * as Sinon from 'sinon' 3 | import { ExecuteQuery } from '../../../lib/query-builders/mixin/ExecuteQuery' 4 | import { isPromise } from '../../../lib/util/isPromise' 5 | 6 | describe('ExecuteQuery', function() { 7 | const functions = ['count', 'update', 'delete', 'restore', 'execute'] 8 | 9 | for (const func of functions) { 10 | describe(`.${func}()`, function() { 11 | it(`calls and returns to handler.getQueryExecutor().${func}()`, async function() { 12 | const result = {} 13 | const queryExecutor = { 14 | [func]: async function() { 15 | return result 16 | } 17 | } 18 | const handler = { 19 | getQueryExecutor() { 20 | return queryExecutor 21 | } 22 | } 23 | 24 | const spy = Sinon.spy(queryExecutor, func) 25 | 26 | const queryBuilder = { 27 | handler: handler 28 | } 29 | 30 | const callResult = ExecuteQuery[func].call(queryBuilder) 31 | expect(isPromise(callResult)).toBe(true) 32 | expect((await callResult) === result).toBe(true) 33 | expect(spy.calledWith()).toBe(true) 34 | }) 35 | }) 36 | } 37 | }) 38 | -------------------------------------------------------------------------------- /test/query-builders/mixin/RelationQuery.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import * as Sinon from 'sinon' 3 | import { RelationQuery } from '../../../lib/query-builders/mixin/RelationQuery' 4 | 5 | describe('RelationQuery', function() { 6 | describe('.with()', function() { 7 | it('flattens argument and calls handler.setEagerRelations() then returns this', function() { 8 | const queryBuilder = { 9 | handler: { 10 | setEagerRelations() {} 11 | } 12 | } 13 | 14 | const spy = Sinon.spy(queryBuilder.handler, 'setEagerRelations') 15 | 16 | expect(RelationQuery.with.apply(queryBuilder, ['a', ['b', 'c'], 'd']) === queryBuilder).toBe(true) 17 | expect(spy.calledWith(['a', 'b', 'c', 'd'])).toBe(true) 18 | }) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /test/query-builders/shared/DefaultConvention.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { DefaultConvention } from '../../../lib/query-builders/shared/DefaultConvention' 3 | 4 | describe('DefaultConvention', function() { 5 | const convention = new DefaultConvention() 6 | 7 | describe('.formatFieldName()', function() { 8 | it('simply returns name from parameter', function() { 9 | const dataList = { 10 | test: 'test', 11 | id: 'id' 12 | } 13 | 14 | for (const name in dataList) { 15 | expect(convention.formatFieldName(name)).toEqual(dataList[name]) 16 | } 17 | }) 18 | }) 19 | 20 | describe('.getNullValueFor()', function() { 21 | it('simply returns null', function() { 22 | const dataList = { 23 | // tslint:disable-next-line 24 | test: null, 25 | // tslint:disable-next-line 26 | id: null 27 | } 28 | 29 | for (const name in dataList) { 30 | expect(convention.getNullValueFor(name)).toBeNull() 31 | } 32 | }) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /test/util/factory.test.ts: -------------------------------------------------------------------------------- 1 | import 'jest' 2 | import { make_collection } from '../../lib/util/factory' 3 | const collect = require('collect.js') 4 | 5 | const CollectionPrototype = Object.getPrototypeOf(collect([])) 6 | 7 | describe('make_collection()', function() { 8 | it('makes an instance of collection from collect() of the collect.js library', function() { 9 | const data = [1, 2, 3] 10 | const result = make_collection(data) 11 | expect(result.all() === data).toBe(true) 12 | expect(Object.getPrototypeOf(result) === CollectionPrototype).toBe(true) 13 | }) 14 | 15 | it('maps to convert data and make an instance of collection from the collect.js library', function() { 16 | const data = [1, 2, 3] 17 | const result = make_collection(data, i => i * 2) 18 | expect(result.all() === data).toBe(false) 19 | expect(result.all()).toEqual([2, 4, 6]) 20 | expect(Object.getPrototypeOf(result) === CollectionPrototype).toBe(true) 21 | }) 22 | }) 23 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2017", 5 | "experimentalDecorators": true, 6 | "moduleResolution": "node", 7 | "outDir": "dist", 8 | "types": ["node"], 9 | "lib": ["es2017"], 10 | "noImplicitReturns": true, 11 | "noImplicitThis": true, 12 | "noImplicitAny": true, 13 | "strictNullChecks": true, 14 | "suppressImplicitAnyIndexErrors": true, 15 | "noUnusedLocals": true, 16 | "skipDefaultLibCheck": true, 17 | "skipLibCheck": true 18 | }, 19 | "include": ["./lib/**/*.ts", "./syntax/**/*.ts", "./test/**/*.ts"], 20 | "exclude": ["node_modules", "build"] 21 | } 22 | --------------------------------------------------------------------------------