namirasoft-field-node 1.4.21 → 1.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/NSFTables.d.ts +6 -6
- package/dist/database/NSFTables.js +13 -22
- package/dist/database/NSFTables.js.map +1 -1
- package/dist/database/table/EntityCategoryTable.d.ts +2 -2
- package/dist/database/table/EntityCategoryTable.js.map +1 -1
- package/package.json +2 -2
- package/src/database/NSFTables.ts +17 -28
- package/src/database/table/EntityCategoryTable.ts +2 -2
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseSequelizeDatabase, BaseSequelizeModel, BaseSequelizeTable } from "namirasoft-node-mysql";
|
|
2
2
|
import { EntityCategoryTable } from "./table/EntityCategoryTable";
|
|
3
3
|
import { EntityFieldTable } from "./table/EntityFieldTable";
|
|
4
4
|
import { EntityTagTable } from "./table/EntityTagTable";
|
|
5
5
|
import { NSABaseApplication } from "namirasoft-account-node";
|
|
6
|
-
import { Includeable,
|
|
6
|
+
import { Includeable, Transaction } from 'sequelize';
|
|
7
7
|
import { NSFInputRow } from "../controller/NSFInputRow";
|
|
8
8
|
import { ObjectSchema } from "namirasoft-schema";
|
|
9
|
-
export declare class NSFTables<Database extends
|
|
9
|
+
export declare class NSFTables<Database extends BaseSequelizeDatabase> {
|
|
10
10
|
name: string;
|
|
11
11
|
private database;
|
|
12
12
|
entity_category: EntityCategoryTable<Database>;
|
|
13
13
|
entity_field: EntityFieldTable<Database>;
|
|
14
14
|
entity_tag: EntityTagTable<Database>;
|
|
15
15
|
constructor(app: NSABaseApplication<Database>, database: Database);
|
|
16
|
-
init
|
|
16
|
+
init(model: BaseSequelizeTable<BaseSequelizeDatabase, BaseSequelizeModel>): void;
|
|
17
17
|
setSchemaByName(schema: ObjectSchema): void;
|
|
18
18
|
handle_getIncludes(includes: Includeable[]): Includeable[];
|
|
19
|
-
create(user_id: string, entity_id: string,
|
|
20
|
-
update(user_id: string, entity_id: string,
|
|
19
|
+
create(user_id: string, entity_id: string, cft: NSFInputRow, trx: Transaction | null): Promise<void>;
|
|
20
|
+
update(user_id: string, entity_id: string, cft: NSFInputRow, trx: Transaction | null): Promise<void>;
|
|
21
21
|
delete(user_id: string, entity_id: string, trx: Transaction | null): Promise<void>;
|
|
22
22
|
}
|
|
@@ -28,22 +28,13 @@ class NSFTables {
|
|
|
28
28
|
this.entity_tag = new EntityTagTable_1.EntityTagTable(app, database);
|
|
29
29
|
}
|
|
30
30
|
init(model) {
|
|
31
|
-
this.name = model.name;
|
|
31
|
+
this.name = model.model.name;
|
|
32
32
|
this.entity_category.define(this.name + "_category", EntityCategoryAttributes_1.EntityCategoryAttributes);
|
|
33
33
|
this.entity_field.define(this.name + "_field", EntityFieldAttributes_1.EntityFieldAttributes);
|
|
34
34
|
this.entity_tag.define(this.name + "_tag", EntityTagAttributes_1.EntityTagAttributes);
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
model.hasMany(this.entity_field.model);
|
|
40
|
-
this.entity_field.model.belongsTo(model, {
|
|
41
|
-
foreignKey: { name: "entity_id", allowNull: false },
|
|
42
|
-
});
|
|
43
|
-
model.hasMany(this.entity_category.model);
|
|
44
|
-
this.entity_category.model.belongsTo(model, {
|
|
45
|
-
foreignKey: { name: "entity_id", allowNull: false },
|
|
46
|
-
});
|
|
35
|
+
this.entity_category.addForeignKey(model, "entity_id", false);
|
|
36
|
+
this.entity_field.addForeignKey(model, "entity_id", false);
|
|
37
|
+
this.entity_tag.addForeignKey(model, "entity_id", false);
|
|
47
38
|
}
|
|
48
39
|
setSchemaByName(schema) {
|
|
49
40
|
schema.addField(new namirasoft_schema_1.BaseVariableSchema(this.name + "_category", new namirasoft_schema_1.ArraySchema(true, [this.entity_category.getSchemaByName(false, EntityCategoryNames_1.EntityCategoryNames.EntityCategoryInput)])));
|
|
@@ -66,24 +57,24 @@ class NSFTables {
|
|
|
66
57
|
});
|
|
67
58
|
return ans;
|
|
68
59
|
}
|
|
69
|
-
create(user_id, entity_id,
|
|
60
|
+
create(user_id, entity_id, cft, trx) {
|
|
70
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
62
|
return yield this.database.startTransaction((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
72
63
|
var _a;
|
|
73
|
-
for (let i = 0; i <
|
|
74
|
-
yield this.entity_category.create(null, null, user_id, entity_id,
|
|
75
|
-
for (let i = 0; i <
|
|
76
|
-
yield this.entity_field.create(null, null, user_id, entity_id,
|
|
77
|
-
for (let i = 0; i <
|
|
78
|
-
yield this.entity_tag.create(null, null, user_id, entity_id,
|
|
64
|
+
for (let i = 0; i < cft.categories.length; i++)
|
|
65
|
+
yield this.entity_category.create(null, null, user_id, entity_id, cft.categories[i].category_id, trx);
|
|
66
|
+
for (let i = 0; i < cft.fields.length; i++)
|
|
67
|
+
yield this.entity_field.create(null, null, user_id, entity_id, cft.fields[i].field_id, cft.fields[i].value, trx);
|
|
68
|
+
for (let i = 0; i < cft.tags.length; i++)
|
|
69
|
+
yield this.entity_tag.create(null, null, user_id, entity_id, cft.tags[i].name, cft.tags[i].value, (_a = cft.tags[i].description) !== null && _a !== void 0 ? _a : "", trx);
|
|
79
70
|
}), trx);
|
|
80
71
|
});
|
|
81
72
|
}
|
|
82
|
-
update(user_id, entity_id,
|
|
73
|
+
update(user_id, entity_id, cft, trx) {
|
|
83
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
75
|
return yield this.database.startTransaction((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
85
76
|
yield this.delete(user_id, entity_id, trx);
|
|
86
|
-
yield this.create(user_id, entity_id,
|
|
77
|
+
yield this.create(user_id, entity_id, cft, trx);
|
|
87
78
|
}), trx);
|
|
88
79
|
});
|
|
89
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NSFTables.js","sourceRoot":"","sources":["../../src/database/NSFTables.ts"],"names":[],"mappings":";;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UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;YAC7D,CAAC,CAAA,EAAE,GAAG,CAAC,CAAC;QACZ,CAAC;KAAA;CACJ;AA9ED,8BA8EC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseSequelizeDatabase, BaseSequelizeTable } from "namirasoft-node-mysql";
|
|
2
2
|
import { Transaction } from "sequelize";
|
|
3
3
|
import { EntityCategoryModel } from "../model/EntityCategoryModel";
|
|
4
4
|
import { ObjectSchema } from "namirasoft-schema";
|
|
5
5
|
import { SessionRow } from "namirasoft-account";
|
|
6
6
|
import { NSABaseApplication } from "namirasoft-account-node";
|
|
7
7
|
import { AccessRow } from "namirasoft-access";
|
|
8
|
-
export declare class EntityCategoryTable<Database extends
|
|
8
|
+
export declare class EntityCategoryTable<Database extends BaseSequelizeDatabase> extends BaseSequelizeTable<Database, EntityCategoryModel> {
|
|
9
9
|
app: NSABaseApplication<Database>;
|
|
10
10
|
constructor(app: NSABaseApplication<Database>, database: Database);
|
|
11
11
|
getShortName(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCategoryTable.js","sourceRoot":"","sources":["../../../src/database/table/EntityCategoryTable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"EntityCategoryTable.js","sourceRoot":"","sources":["../../../src/database/table/EntityCategoryTable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAkF;AAKlF,wEAAqE;AAIrE,MAAa,mBAA4D,SAAQ,0CAAiD;IAG9H,YAAY,GAAiC,EAAE,QAAkB;QAE7D,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IACQ,YAAY;QAEjB,OAAO,EAAE,CAAC;IACd,CAAC;IACQ,cAAc;QAEnB,OAAO,MAAM,CAAC,IAAI,CAAC,y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AE,GAAG,EAAE,CAAC,CAAC;YACjD,CAAC,CAAA,CAAC,CAAC;QACP,CAAC;KAAA;IACK,MAAM,CAAC,MAAwB,EAAE,OAA0B,EAAE,OAAe,EAAE,EAAU,EAAE,GAAuB;;YAEnH,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAS,EAAE;gBAEvD,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;gBAC5D,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;gBACzC,OAAO,IAAI,CAAC;YAChB,CAAC,CAAA,CAAC,CAAC;QACP,CAAC;KAAA;IACK,SAAS,CAAC,OAAe,EAAE,SAAiB,EAAE,GAAuB;;YAEvE,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;QAClF,CAAC;KAAA;CACJ;AA5DD,kDA4DC"}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"framework": "npm",
|
|
9
9
|
"application": "package",
|
|
10
10
|
"private": false,
|
|
11
|
-
"version": "1.4.
|
|
11
|
+
"version": "1.4.22",
|
|
12
12
|
"author": "Amir Abolhasani",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"namirasoft-account-node": "^1.4.66",
|
|
22
22
|
"namirasoft-core": "^1.4.39",
|
|
23
23
|
"namirasoft-node": "^1.4.33",
|
|
24
|
-
"namirasoft-node-mysql": "^1.4.
|
|
24
|
+
"namirasoft-node-mysql": "^1.4.14",
|
|
25
25
|
"namirasoft-schema": "^1.4.22"
|
|
26
26
|
},
|
|
27
27
|
"bin": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseSequelizeDatabase, BaseSequelizeModel, BaseSequelizeTable } from "namirasoft-node-mysql";
|
|
2
2
|
import { EntityCategoryTable } from "./table/EntityCategoryTable";
|
|
3
3
|
import { EntityFieldTable } from "./table/EntityFieldTable";
|
|
4
4
|
import { EntityTagTable } from "./table/EntityTagTable";
|
|
@@ -6,14 +6,14 @@ import { NSABaseApplication } from "namirasoft-account-node";
|
|
|
6
6
|
import { EntityTagAttributes } from "./attributes/EntityTagAttributes";
|
|
7
7
|
import { EntityFieldAttributes } from "./attributes/EntityFieldAttributes";
|
|
8
8
|
import { EntityCategoryAttributes } from "./attributes/EntityCategoryAttributes";
|
|
9
|
-
import { Includeable,
|
|
9
|
+
import { Includeable, Transaction } from 'sequelize';
|
|
10
10
|
import { NSFInputRow } from "../controller/NSFInputRow";
|
|
11
11
|
import { ArraySchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
12
12
|
import { EntityCategoryNames } from "../enum/EntityCategoryNames";
|
|
13
13
|
import { EntityFieldNames } from "../enum/EntityFieldNames";
|
|
14
14
|
import { EntityTagNames } from "../enum/EntityTagNames";
|
|
15
15
|
|
|
16
|
-
export class NSFTables<Database extends
|
|
16
|
+
export class NSFTables<Database extends BaseSequelizeDatabase>
|
|
17
17
|
{
|
|
18
18
|
name!: string;
|
|
19
19
|
private database: Database;
|
|
@@ -27,28 +27,17 @@ export class NSFTables<Database extends BaseMySqlDatabase>
|
|
|
27
27
|
this.entity_field = new EntityFieldTable<Database>(app, database);
|
|
28
28
|
this.entity_tag = new EntityTagTable<Database>(app, database);
|
|
29
29
|
}
|
|
30
|
-
init
|
|
30
|
+
init(model: BaseSequelizeTable<BaseSequelizeDatabase, BaseSequelizeModel>)
|
|
31
31
|
{
|
|
32
|
-
this.name = model.name;
|
|
32
|
+
this.name = model.model.name;
|
|
33
33
|
this.entity_category.define(this.name + "_category", EntityCategoryAttributes);
|
|
34
34
|
this.entity_field.define(this.name + "_field", EntityFieldAttributes);
|
|
35
35
|
this.entity_tag.define(this.name + "_tag", EntityTagAttributes);
|
|
36
36
|
|
|
37
37
|
// set foreignKeys
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
model.hasMany(this.entity_field.model);
|
|
44
|
-
this.entity_field.model.belongsTo(model, {
|
|
45
|
-
foreignKey: { name: "entity_id", allowNull: false },
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
model.hasMany(this.entity_category.model);
|
|
49
|
-
this.entity_category.model.belongsTo(model, {
|
|
50
|
-
foreignKey: { name: "entity_id", allowNull: false },
|
|
51
|
-
});
|
|
38
|
+
this.entity_category.addForeignKey(model, "entity_id", false);
|
|
39
|
+
this.entity_field.addForeignKey(model, "entity_id", false);
|
|
40
|
+
this.entity_tag.addForeignKey(model, "entity_id", false);
|
|
52
41
|
}
|
|
53
42
|
setSchemaByName(schema: ObjectSchema)
|
|
54
43
|
{
|
|
@@ -73,24 +62,24 @@ export class NSFTables<Database extends BaseMySqlDatabase>
|
|
|
73
62
|
});
|
|
74
63
|
return ans;
|
|
75
64
|
}
|
|
76
|
-
async create(user_id: string, entity_id: string,
|
|
65
|
+
async create(user_id: string, entity_id: string, cft: NSFInputRow, trx: Transaction | null)
|
|
77
66
|
{
|
|
78
67
|
return await this.database.startTransaction(async trx =>
|
|
79
68
|
{
|
|
80
|
-
for (let i = 0; i <
|
|
81
|
-
await this.entity_category.create(null, null, user_id, entity_id,
|
|
82
|
-
for (let i = 0; i <
|
|
83
|
-
await this.entity_field.create(null, null, user_id, entity_id,
|
|
84
|
-
for (let i = 0; i <
|
|
85
|
-
await this.entity_tag.create(null, null, user_id, entity_id,
|
|
69
|
+
for (let i = 0; i < cft.categories.length; i++)
|
|
70
|
+
await this.entity_category.create(null, null, user_id, entity_id, cft.categories[i].category_id, trx);
|
|
71
|
+
for (let i = 0; i < cft.fields.length; i++)
|
|
72
|
+
await this.entity_field.create(null, null, user_id, entity_id, cft.fields[i].field_id, cft.fields[i].value, trx);
|
|
73
|
+
for (let i = 0; i < cft.tags.length; i++)
|
|
74
|
+
await this.entity_tag.create(null, null, user_id, entity_id, cft.tags[i].name, cft.tags[i].value, cft.tags[i].description ?? "", trx);
|
|
86
75
|
}, trx);
|
|
87
76
|
}
|
|
88
|
-
async update(user_id: string, entity_id: string,
|
|
77
|
+
async update(user_id: string, entity_id: string, cft: NSFInputRow, trx: Transaction | null)
|
|
89
78
|
{
|
|
90
79
|
return await this.database.startTransaction(async trx =>
|
|
91
80
|
{
|
|
92
81
|
await this.delete(user_id, entity_id, trx);
|
|
93
|
-
await this.create(user_id, entity_id,
|
|
82
|
+
await this.create(user_id, entity_id, cft, trx);
|
|
94
83
|
}, trx);
|
|
95
84
|
}
|
|
96
85
|
async delete(user_id: string, entity_id: string, trx: Transaction | null)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseSequelizeDatabase, BaseSequelizeTable } from "namirasoft-node-mysql";
|
|
2
2
|
import { Transaction } from "sequelize";
|
|
3
3
|
import { EntityCategoryModel } from "../model/EntityCategoryModel";
|
|
4
4
|
import { ObjectSchema } from "namirasoft-schema";
|
|
@@ -7,7 +7,7 @@ import { EntityCategoryNames } from "../../enum/EntityCategoryNames";
|
|
|
7
7
|
import { NSABaseApplication } from "namirasoft-account-node";
|
|
8
8
|
import { AccessRow } from "namirasoft-access";
|
|
9
9
|
|
|
10
|
-
export class EntityCategoryTable<Database extends
|
|
10
|
+
export class EntityCategoryTable<Database extends BaseSequelizeDatabase> extends BaseSequelizeTable<Database, EntityCategoryModel>
|
|
11
11
|
{
|
|
12
12
|
public app: NSABaseApplication<Database>;
|
|
13
13
|
constructor(app: NSABaseApplication<Database>, database: Database)
|