Comparing version 1.0.5 to 1.1.0-beta
import Component from './Component'; | ||
import SequelizeAdapter from '../orm-adapters/SequelizeAdapter'; | ||
import Serializer from '../rest/Serializer'; | ||
@@ -47,6 +46,5 @@ /** | ||
* The key of the adapter to be used should be specified in [[orm]] | ||
* By default, support for Sequelize ORM is provided. | ||
*/ | ||
static ormAdapterClasses: { | ||
sequelize: typeof SequelizeAdapter; | ||
[key: string]: any; | ||
}; | ||
@@ -53,0 +51,0 @@ private static _ormAdapter; |
@@ -15,2 +15,3 @@ "use strict"; | ||
const SequelizeAdapter_1 = require("../orm-adapters/SequelizeAdapter"); | ||
const MongooseAdapter_1 = require("../orm-adapters/MongooseAdapter"); | ||
const sequelize_1 = require("sequelize"); | ||
@@ -91,4 +92,4 @@ const View_1 = require("./View"); | ||
static getORMAdapter() { | ||
if (this._ormAdapter === undefined) | ||
this._ormAdapter = new this.ormAdapterClasses[this.orm]({}); | ||
if (this._ormAdapter === undefined && this.orm !== undefined) | ||
this._ormAdapter = new this.ormAdapterClasses[(this.ormModelClass()).ormKey || this.orm]({}); | ||
return this._ormAdapter; | ||
@@ -161,5 +162,7 @@ } | ||
* The key of the adapter to be used should be specified in [[orm]] | ||
* By default, support for Sequelize ORM is provided. | ||
*/ | ||
Application.ormAdapterClasses = { sequelize: SequelizeAdapter_1.default }; | ||
Application.ormAdapterClasses = { | ||
mongoose: MongooseAdapter_1.default, | ||
sequelize: SequelizeAdapter_1.default | ||
}; | ||
/** | ||
@@ -180,6 +183,7 @@ * The model class for the ORM being used. Eg:- [[sequelize.Model]] for Sequelize | ||
try { | ||
let model = require('../../../../orm-model-config.cjs'); | ||
let model = require('../../../../orm-model-config.js'); // require('../pkgtest/orm-model-config.js'); | ||
return model; | ||
} | ||
catch (innerE) { } | ||
catch (innerE) { | ||
} | ||
return sequelize_1.Model; | ||
@@ -186,0 +190,0 @@ } |
@@ -105,9 +105,11 @@ import { ActiveDataProvider } from '..'; | ||
* export class Event extends Model { | ||
* attributeLabels = { | ||
* firstName: 'First Name', | ||
* ... | ||
* getAttributeLabels() { | ||
* return { | ||
* firstName: 'First Name', | ||
* ... | ||
* } | ||
* }; | ||
* ``` | ||
*/ | ||
protected attributeLabels: { | ||
getAttributeLabels: () => { | ||
[key: string]: string; | ||
@@ -122,11 +124,16 @@ }; | ||
* export class Event extends Model { | ||
* attributeHints = { | ||
* isPublic: 'Whether the post should be visible for not logged in users', | ||
* ... | ||
* getAttributeHints() { | ||
* return { | ||
* firstName: 'First Name', | ||
* ... | ||
* } | ||
* }; | ||
* ``` | ||
*/ | ||
protected attributeHints: { | ||
protected getAttributeHints: () => { | ||
[key: string]: string; | ||
}; | ||
constructor(config?: { | ||
[key: string]: any; | ||
}); | ||
/** | ||
@@ -133,0 +140,0 @@ * Returns the text label for the specified attribute. |
@@ -106,4 +106,4 @@ "use strict"; | ||
class Model extends ORMModel { | ||
constructor() { | ||
super(...arguments); | ||
constructor(config = {}) { | ||
super(config); | ||
/** | ||
@@ -120,9 +120,11 @@ * Validation errors (attribute name => array of errors) | ||
* export class Event extends Model { | ||
* attributeLabels = { | ||
* firstName: 'First Name', | ||
* ... | ||
* getAttributeLabels() { | ||
* return { | ||
* firstName: 'First Name', | ||
* ... | ||
* } | ||
* }; | ||
* ``` | ||
*/ | ||
this.attributeLabels = {}; | ||
this.getAttributeLabels = () => ({}); | ||
/** | ||
@@ -135,9 +137,12 @@ * Attribute hints are mainly used for display purpose. For example, given an attribute | ||
* export class Event extends Model { | ||
* attributeHints = { | ||
* isPublic: 'Whether the post should be visible for not logged in users', | ||
* ... | ||
* getAttributeHints() { | ||
* return { | ||
* firstName: 'First Name', | ||
* ... | ||
* } | ||
* }; | ||
* ``` | ||
*/ | ||
this.attributeHints = {}; | ||
this.getAttributeHints = () => ({}); | ||
Object.assign(this, config); | ||
} | ||
@@ -152,4 +157,5 @@ /** | ||
getAttributeLabel(attribute) { | ||
return this.attributeLabels[attribute] !== undefined | ||
? this.attributeLabels[attribute] | ||
var _a, _b; | ||
return ((_b = (_a = this.getAttributeLabels) === null || _a === void 0 ? void 0 : _a.call(this)) === null || _b === void 0 ? void 0 : _b[attribute]) !== undefined | ||
? this.getAttributeLabels()[attribute] | ||
: Inflector.humanize(attribute); | ||
@@ -183,3 +189,3 @@ } | ||
getFormName() { | ||
return this.constructor.name; | ||
return this.constructor.modelName || this.constructor.name; | ||
} | ||
@@ -254,3 +260,4 @@ /** | ||
getFirstError(attribute) { | ||
return this._errors[attribute] !== undefined ? this._errors[attribute] : null; | ||
var _a, _b; | ||
return ((_a = this._errors) === null || _a === void 0 ? void 0 : _a[attribute]) !== undefined ? (_b = this._errors) === null || _b === void 0 ? void 0 : _b[attribute] : null; | ||
} | ||
@@ -265,4 +272,5 @@ /** | ||
getAttributeHint(attribute) { | ||
let hints = this.attributeHints; | ||
return hints[attribute] !== undefined ? hints[attribute] : ''; | ||
var _a; | ||
let hints = (_a = this.getAttributeHints) === null || _a === void 0 ? void 0 : _a.call(this); | ||
return (hints === null || hints === void 0 ? void 0 : hints[attribute]) !== undefined ? hints === null || hints === void 0 ? void 0 : hints[attribute] : ''; | ||
} | ||
@@ -284,3 +292,4 @@ /** | ||
hasErrors(attribute = null) { | ||
return attribute === null ? Object.keys(this._errors).length > 0 : this._errors[attribute] !== undefined; | ||
var _a; | ||
return attribute === null ? Object.keys(this._errors).length > 0 : ((_a = this._errors) === null || _a === void 0 ? void 0 : _a[attribute]) !== undefined; | ||
} | ||
@@ -329,2 +338,3 @@ /** | ||
yield ormAdapter.validate(this); | ||
// | ||
return !this.hasErrors(); | ||
@@ -338,8 +348,9 @@ }); | ||
clearErrors(attribute = null) { | ||
var _a; | ||
if (attribute === null) | ||
this._errors = {}; | ||
else | ||
delete this._errors[attribute]; | ||
(_a = this._errors) === null || _a === void 0 ? true : delete _a[attribute]; | ||
} | ||
} | ||
exports.default = Model; |
@@ -121,3 +121,3 @@ "use strict"; | ||
if (Object.keys(sort.attributes).length === 0) { | ||
const attributes = this.ormAdapter.attributes(); | ||
const attributes = this.ormAdapter.allAttributes !== undefined ? this.ormAdapter.allAttributes(model) : this.ormAdapter.attributes(); | ||
for (const attribute of attributes) { | ||
@@ -124,0 +124,0 @@ sort.attributes[attribute] = { |
@@ -145,3 +145,3 @@ "use strict"; | ||
const model = this.grid.filterModel; | ||
if (this.filter !== false && model instanceof Model_1.default && this.filterAttribute !== undefined) { | ||
if (this.filter !== false && typeof model.getFormName === 'function' && this.filterAttribute !== undefined) { | ||
const options = Object.assign({ maxlength: true }, this.filterInputOptions); | ||
@@ -148,0 +148,0 @@ return Html_1.default.activeTextInput(model, this.filterAttribute, options); |
@@ -132,2 +132,4 @@ import Component from '../base/Component'; | ||
static strcmp(str1: any, str2: any): 1 | 0 | -1; | ||
static resolveDotStructuredObject(object: any, attribute: any): any; | ||
static findValuesByPrefix(object: any, prefix: any): {}; | ||
} |
@@ -560,3 +560,20 @@ "use strict"; | ||
} | ||
static resolveDotStructuredObject(object, attribute) { | ||
let nests = attribute.split('.'); | ||
let dotResolved = this.findValuesByPrefix(object, nests[0] + "."); | ||
if (Object.values(dotResolved).length === 0) | ||
return Object.assign(Object.assign({}, object), dotResolved); | ||
return { [nests[0]]: this.resolveDotStructuredObject(dotResolved, nests.slice(1).join('.')) }; | ||
} | ||
static findValuesByPrefix(object, prefix) { | ||
let output = {}; | ||
for (var property in object) { // | ||
if (object.hasOwnProperty(property) && | ||
property.toString().startsWith(prefix)) { // | ||
output[property.toString().split(prefix)[1]] = object[property]; | ||
} | ||
} | ||
return output; | ||
} | ||
} | ||
exports.default = DataHelper; |
@@ -31,1 +31,2 @@ export { default as ActiveDataProvider } from './data/ActiveDataProvider'; | ||
export { default as SequelizeAdapter } from './orm-adapters/SequelizeAdapter'; | ||
export { default as MongooseAdapter } from './orm-adapters/MongooseAdapter'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SequelizeAdapter = exports.ORMAdapter = exports.SerialColumn = exports.RadioButtonColumn = exports.CheckboxColumn = exports.ActiveField = exports.ActionColumn = exports.Serializer = exports.Widget = exports.View = exports.Sort = exports.Pagination = exports.Model = exports.ListView = exports.LinkSorter = exports.LinkPager = exports.Html = exports.GridView = exports.DataProvider = exports.DataHelper = exports.DataColumn = exports.Component = exports.Column = exports.CollectionView = exports.ArrayDataProvider = exports.Application = exports.ActiveForm = exports.ActiveDataProvider = void 0; | ||
exports.MongooseAdapter = exports.SequelizeAdapter = exports.ORMAdapter = exports.SerialColumn = exports.RadioButtonColumn = exports.CheckboxColumn = exports.ActiveField = exports.ActionColumn = exports.Serializer = exports.Widget = exports.View = exports.Sort = exports.Pagination = exports.Model = exports.ListView = exports.LinkSorter = exports.LinkPager = exports.Html = exports.GridView = exports.DataProvider = exports.DataHelper = exports.DataColumn = exports.Component = exports.Column = exports.CollectionView = exports.ArrayDataProvider = exports.Application = exports.ActiveForm = exports.ActiveDataProvider = void 0; | ||
var ActiveDataProvider_1 = require("./data/ActiveDataProvider"); | ||
@@ -60,2 +60,4 @@ Object.defineProperty(exports, "ActiveDataProvider", { enumerable: true, get: function () { return ActiveDataProvider_1.default; } }); | ||
Object.defineProperty(exports, "SequelizeAdapter", { enumerable: true, get: function () { return SequelizeAdapter_1.default; } }); | ||
var MongooseAdapter_1 = require("./orm-adapters/MongooseAdapter"); | ||
Object.defineProperty(exports, "MongooseAdapter", { enumerable: true, get: function () { return MongooseAdapter_1.default; } }); | ||
// export { | ||
@@ -62,0 +64,0 @@ // ActionColumn, |
@@ -1,5 +0,4 @@ | ||
import { Model } from "sequelize"; | ||
declare class Me extends Model { | ||
declare class Model { | ||
static ormKey: string; | ||
test: string; | ||
} | ||
export default Me; |
@@ -1,11 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const sequelize_1 = require("sequelize"); | ||
class Me extends sequelize_1.Model { | ||
class Model { | ||
constructor() { | ||
super(...arguments); | ||
this.test = 'Mahesh'; | ||
this.test = 'testv'; | ||
} | ||
} | ||
console.log('me', Me); | ||
exports.default = Me; | ||
Model.ormKey = 'mongoose'; | ||
module.exports = Model; |
@@ -16,3 +16,2 @@ "use strict"; | ||
pkgtest_lib_1.Application.setViewPath(path.join(__dirname, 'views')); | ||
pkgtest_lib_1.Application.ormAdapterClasses['mongoose'] = {}; | ||
//Pwoli.setORMAdapter(new Pwoli.ormAdapterClasses['sequelize']()); | ||
@@ -50,3 +49,3 @@ const url = require('url'); | ||
//Pwoli.orm = 'mongoose' | ||
//console.log('orma', Pwoli.ormAdapterClasses, Pwoli.orm, Pwoli.getORMAdapter()) | ||
// | ||
const uri = url.parse(req.url).pathname; | ||
@@ -77,7 +76,6 @@ let filename = path.join(process.cwd(), uri); | ||
else if (req.url.includes('items/create') || req.url.includes('items/update')) { | ||
console.log('req-query', req.url.substring(req.url.lastIndexOf('/') + 1)); | ||
const company = req.url.includes('items/create') | ||
? new pkgtest_models_1.Company() | ||
: yield pkgtest_models_1.Company.findOne({ where: { id: req.url.substring(req.url.lastIndexOf('/') + 1) } }); | ||
//console.log('company-test', company); | ||
// | ||
if (req.method === 'POST') { | ||
@@ -99,3 +97,2 @@ let body = ''; | ||
} | ||
console.log('before-save', post, company.load(post) && (yield company.verify()), company.eventId); | ||
if (company.load(post) && (yield company.verify())) { | ||
@@ -108,3 +105,3 @@ //company.eventId = 1; | ||
.catch((error) => console.log('save-error', error)); | ||
//console.log('after-save', await company.save()) | ||
// | ||
// res.writeHead(301, | ||
@@ -134,3 +131,3 @@ // { Location: '/form?success=true' } | ||
let sort = dataProvider.getSort(); | ||
//console.log('dp-sort', sort) | ||
// | ||
sort.attributes['event.title'] = { | ||
@@ -213,3 +210,2 @@ asc: ['event', 'title', 'asc'], | ||
}); | ||
console.log('api-model', model); | ||
} | ||
@@ -216,0 +212,0 @@ yield dataProvider.setModels(models); |
{ | ||
"name": "pwoli", | ||
"version": "1.0.5", | ||
"version": "1.1.0-beta", | ||
"description": "", | ||
@@ -24,3 +24,6 @@ "main": "lib/index.js", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^4.2.4" | ||
"typescript": "^4.2.4", | ||
"mongoose": "^6.7.0", | ||
"mysql2": "^2.2.5", | ||
"sequelize": "*" | ||
}, | ||
@@ -32,5 +35,3 @@ "dependencies": { | ||
"inflected": "^2.1.0", | ||
"mysql2": "^2.2.5", | ||
"path": "^0.12.7", | ||
"sequelize": "*", | ||
"typedoc": "^0.22.11", | ||
@@ -37,0 +38,0 @@ "url": "^0.11.0" |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
1463993
7
89
37114
1
11
2
5
2
- Removedmysql2@^2.2.5
- Removedsequelize@*
- Removed@types/debug@4.1.12(transitive)
- Removed@types/ms@0.7.34(transitive)
- Removed@types/node@22.5.5(transitive)
- Removed@types/validator@13.12.1(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddenque@2.1.0(transitive)
- Removeddottie@2.0.6(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedinflection@1.13.4(transitive)
- Removedis-property@1.0.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlong@4.0.0(transitive)
- Removedlru-cache@6.0.07.18.3(transitive)
- Removedmoment@2.30.1(transitive)
- Removedmoment-timezone@0.5.45(transitive)
- Removedms@2.1.3(transitive)
- Removedmysql2@2.3.3(transitive)
- Removednamed-placeholders@1.1.3(transitive)
- Removedpg-connection-string@2.6.4(transitive)
- Removedretry-as-promised@7.0.4(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsemver@7.6.3(transitive)
- Removedseq-queue@0.0.5(transitive)
- Removedsequelize@6.37.3(transitive)
- Removedsequelize-pool@7.1.0(transitive)
- Removedsqlstring@2.3.3(transitive)
- Removedtoposort-class@1.0.1(transitive)
- Removedundici-types@6.19.8(transitive)
- Removeduuid@8.3.2(transitive)
- Removedvalidator@13.12.0(transitive)
- Removedwkx@0.5.0(transitive)
- Removedyallist@4.0.0(transitive)