@chevre/domain 24.0.0 → 24.1.0-alpha.0

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.
@@ -1,44 +1,11 @@
1
- import type { Connection, FilterQuery } from 'mongoose';
1
+ import type { Connection } from 'mongoose';
2
2
  import { factory } from '../factory';
3
- import { IProductModel } from './mongoose/schemas/productModel';
4
- type IKeyOfProjection = keyof IProductModel | '_id';
5
- type ISearchConditions = Pick<factory.product.ISearchConditions, 'id' | 'limit' | 'page' | 'project'> & {
6
- category?: {
7
- codeValue?: {
8
- $in?: string[];
9
- };
10
- inCodeSet?: {
11
- identifier?: {
12
- $eq?: string;
13
- };
14
- };
15
- };
16
- };
17
3
  /**
18
4
  * プロダクトモデルリポジトリ
19
5
  */
20
6
  export declare class ProductModelRepo {
21
7
  private readonly productModelModel;
22
8
  constructor(connection: Connection);
23
- static CREATE_MONGO_CONDITIONS(params: ISearchConditions): FilterQuery<factory.product.IProduct>[];
24
- search(conditions: ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<IProductModel[]>;
25
- deleteById(params: {
26
- id: string;
27
- }): Promise<void>;
28
- /**
29
- * プロダクトを保管する
30
- */
31
- save(params: {
32
- /**
33
- * idを指定すれば更新
34
- */
35
- id?: string;
36
- $set: Omit<IProductModel, 'id'> & {
37
- id?: never;
38
- };
39
- }): Promise<{
40
- id: string;
41
- }>;
42
9
  /**
43
10
  * 区分から同期する
44
11
  */
@@ -57,9 +24,4 @@ export declare class ProductModelRepo {
57
24
  id: string;
58
25
  };
59
26
  }): Promise<void>;
60
- unsetUnnecessaryFields(params: {
61
- filter: any;
62
- $unset: any;
63
- }): Promise<import("mongoose").UpdateWriteOpResult>;
64
27
  }
65
- export {};
@@ -2,8 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProductModelRepo = void 0;
4
4
  const factory_1 = require("../factory");
5
- const settings_1 = require("../settings");
5
+ // import { MONGO_MAX_TIME_MS } from '../settings';
6
6
  const productModel_1 = require("./mongoose/schemas/productModel");
7
+ // type IKeyOfProjection = keyof IProductModel | '_id';
8
+ // type ISearchConditions = Pick<factory.product.ISearchConditions, 'id' | 'limit' | 'page' | 'project'> & {
9
+ // category?: {
10
+ // codeValue?: { $in?: string[] };
11
+ // inCodeSet?: { identifier?: { $eq?: string } };
12
+ // };
13
+ // };
7
14
  /**
8
15
  * プロダクトモデルリポジトリ
9
16
  */
@@ -12,97 +19,112 @@ class ProductModelRepo {
12
19
  constructor(connection) {
13
20
  this.productModelModel = connection.model(productModel_1.modelName, (0, productModel_1.createSchema)());
14
21
  }
15
- static CREATE_MONGO_CONDITIONS(params) {
16
- // MongoDB検索条件
17
- const andConditions = [];
18
- const projectIdEq = params.project?.id?.$eq;
19
- if (typeof projectIdEq === 'string') {
20
- andConditions.push({
21
- 'project.id': { $eq: projectIdEq }
22
- });
23
- }
24
- const idEq = params.id?.$eq;
25
- if (typeof idEq === 'string') {
26
- andConditions.push({ _id: { $eq: idEq } });
27
- }
28
- const idIn = params.id?.$in;
29
- if (Array.isArray(idIn)) {
30
- andConditions.push({ _id: { $in: idIn } });
31
- }
32
- const categoryCodeValueIn = params.category?.codeValue?.$in;
33
- if (Array.isArray(categoryCodeValueIn)) {
34
- andConditions.push({ 'category.codeValue': { $exists: true, $in: categoryCodeValueIn } });
35
- }
36
- const categoryInCodeSetIdentifierEq = params.category?.inCodeSet?.identifier?.$eq;
37
- if (typeof categoryInCodeSetIdentifierEq === 'string') {
38
- andConditions.push({ 'category.inCodeSet.identifier': { $exists: true, $eq: categoryInCodeSetIdentifierEq } });
39
- }
40
- return andConditions;
41
- }
42
- async search(conditions, inclusion, exclusion) {
43
- const andConditions = ProductModelRepo.CREATE_MONGO_CONDITIONS(conditions);
44
- let projection = {};
45
- if (Array.isArray(inclusion) && inclusion.length > 0) {
46
- inclusion.forEach((field) => {
47
- projection[field] = 1;
48
- });
49
- }
50
- else {
51
- projection = {
52
- __v: 0,
53
- createdAt: 0,
54
- updatedAt: 0
55
- };
56
- if (Array.isArray(exclusion) && exclusion.length > 0) {
57
- exclusion.forEach((field) => {
58
- projection[field] = 0;
59
- });
60
- }
61
- }
62
- const query = this.productModelModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
63
- if (typeof conditions.limit === 'number' && conditions.limit > 0) {
64
- const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
65
- query.limit(conditions.limit)
66
- .skip(conditions.limit * (page - 1));
67
- }
68
- // if (conditions.sort?.productID !== undefined) {
69
- // query.sort({ productID: conditions.sort.productID });
70
- // }
71
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
72
- .exec()
73
- .then((docs) => docs.map((doc) => doc.toObject({ virtuals: true })));
74
- }
75
- async deleteById(params) {
76
- await this.productModelModel.findOneAndDelete({ _id: params.id })
77
- .exec();
78
- }
79
- /**
80
- * プロダクトを保管する
81
- */
82
- async save(params) {
83
- let savedId;
84
- if (typeof params.id === 'string') {
85
- // 上書き禁止属性を除外
86
- const { category, id, project, typeOf, ...setFields } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
87
- const updatedDoc = await this.productModelModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
88
- $set: setFields
89
- }, { upsert: false, new: true, projection: { _id: 1 } })
90
- .exec();
91
- if (updatedDoc === null) {
92
- throw new factory_1.factory.errors.NotFound(this.productModelModel.modelName);
93
- }
94
- savedId = updatedDoc.id;
95
- }
96
- else {
97
- const { id, ...createParams } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
98
- const createdDoc = await this.productModelModel.create(createParams);
99
- savedId = createdDoc.id;
100
- }
101
- // if (doc === null) {
102
- // throw new factory.errors.NotFound(this.productModelModel.modelName);
103
- // }
104
- return { id: savedId };
105
- }
22
+ // public static CREATE_MONGO_CONDITIONS(params: ISearchConditions) {
23
+ // // MongoDB検索条件
24
+ // const andConditions: FilterQuery<factory.product.IProduct>[] = [];
25
+ // const projectIdEq = params.project?.id?.$eq;
26
+ // if (typeof projectIdEq === 'string') {
27
+ // andConditions.push({
28
+ // 'project.id': { $eq: projectIdEq }
29
+ // });
30
+ // }
31
+ // const idEq = params.id?.$eq;
32
+ // if (typeof idEq === 'string') {
33
+ // andConditions.push({ _id: { $eq: idEq } });
34
+ // }
35
+ // const idIn = params.id?.$in;
36
+ // if (Array.isArray(idIn)) {
37
+ // andConditions.push({ _id: { $in: idIn } });
38
+ // }
39
+ // const categoryCodeValueIn = params.category?.codeValue?.$in;
40
+ // if (Array.isArray(categoryCodeValueIn)) {
41
+ // andConditions.push({ 'category.codeValue': { $exists: true, $in: categoryCodeValueIn } });
42
+ // }
43
+ // const categoryInCodeSetIdentifierEq = params.category?.inCodeSet?.identifier?.$eq;
44
+ // if (typeof categoryInCodeSetIdentifierEq === 'string') {
45
+ // andConditions.push({ 'category.inCodeSet.identifier': { $exists: true, $eq: categoryInCodeSetIdentifierEq } });
46
+ // }
47
+ // return andConditions;
48
+ // }
49
+ // public async search(
50
+ // conditions: ISearchConditions,
51
+ // inclusion: IKeyOfProjection[],
52
+ // exclusion: IKeyOfProjection[]
53
+ // ): Promise<IProductModel[]> {
54
+ // const andConditions = ProductModelRepo.CREATE_MONGO_CONDITIONS(conditions);
55
+ // let projection: Record<string, number> = {};
56
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
57
+ // inclusion.forEach((field) => {
58
+ // projection[field] = 1;
59
+ // });
60
+ // } else {
61
+ // projection = {
62
+ // __v: 0,
63
+ // createdAt: 0,
64
+ // updatedAt: 0
65
+ // };
66
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
67
+ // exclusion.forEach((field) => {
68
+ // projection[field] = 0;
69
+ // });
70
+ // }
71
+ // }
72
+ // const query = this.productModelModel.find(
73
+ // (andConditions.length > 0) ? { $and: andConditions } : {},
74
+ // projection
75
+ // );
76
+ // if (typeof conditions.limit === 'number' && conditions.limit > 0) {
77
+ // const page: number = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
78
+ // query.limit(conditions.limit)
79
+ // .skip(conditions.limit * (page - 1));
80
+ // }
81
+ // // if (conditions.sort?.productID !== undefined) {
82
+ // // query.sort({ productID: conditions.sort.productID });
83
+ // // }
84
+ // return query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
85
+ // .exec()
86
+ // .then((docs) => docs.map((doc) => doc.toObject({ virtuals: true })));
87
+ // }
88
+ // public async deleteById(params: { id: string }) {
89
+ // await this.productModelModel.findOneAndDelete({ _id: params.id })
90
+ // .exec();
91
+ // }
92
+ // /**
93
+ // * プロダクトを保管する
94
+ // */
95
+ // public async save(params: {
96
+ // /**
97
+ // * idを指定すれば更新
98
+ // */
99
+ // id?: string;
100
+ // $set: Omit<IProductModel, 'id'> & { id?: never };
101
+ // }): Promise<{ id: string }> {
102
+ // let savedId: string;
103
+ // if (typeof params.id === 'string') {
104
+ // // 上書き禁止属性を除外
105
+ // const { category, id, project, typeOf, ...setFields } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
106
+ // const updatedDoc = await this.productModelModel.findOneAndUpdate(
107
+ // { _id: { $eq: params.id } },
108
+ // {
109
+ // $set: setFields
110
+ // },
111
+ // { upsert: false, new: true, projection: { _id: 1 } }
112
+ // )
113
+ // .exec();
114
+ // if (updatedDoc === null) {
115
+ // throw new factory.errors.NotFound(this.productModelModel.modelName);
116
+ // }
117
+ // savedId = updatedDoc.id;
118
+ // } else {
119
+ // const { id, ...createParams } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
120
+ // const createdDoc = await this.productModelModel.create(createParams);
121
+ // savedId = createdDoc.id;
122
+ // }
123
+ // // if (doc === null) {
124
+ // // throw new factory.errors.NotFound(this.productModelModel.modelName);
125
+ // // }
126
+ // return { id: savedId };
127
+ // }
106
128
  /**
107
129
  * 区分から同期する
108
130
  */
@@ -144,9 +166,5 @@ class ProductModelRepo {
144
166
  })
145
167
  .exec();
146
168
  }
147
- async unsetUnnecessaryFields(params) {
148
- return this.productModelModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
149
- .exec();
150
- }
151
169
  }
152
170
  exports.ProductModelRepo = ProductModelRepo;
@@ -66,7 +66,6 @@ import type { PotentialActionRepo } from './repo/potentialAction';
66
66
  import type { PriceSpecificationRepo } from './repo/priceSpecification';
67
67
  import type { ProductRepo } from './repo/product';
68
68
  import type { ProductHasOfferCatalogRepo } from './repo/productHasOfferCatalog';
69
- import type { ProductModelRepo } from './repo/productModel';
70
69
  import type { ProjectRepo } from './repo/project';
71
70
  import type { ProjectMakesOfferRepo } from './repo/projectMakesOffer';
72
71
  import type { OfferRateLimitRepo } from './repo/rateLimit/offer';
@@ -389,10 +388,6 @@ export type ProductHasOfferCatalog = ProductHasOfferCatalogRepo;
389
388
  export declare namespace ProductHasOfferCatalog {
390
389
  function createInstance(...params: ConstructorParameters<typeof ProductHasOfferCatalogRepo>): Promise<ProductHasOfferCatalogRepo>;
391
390
  }
392
- export type ProductModel = ProductModelRepo;
393
- export declare namespace ProductModel {
394
- function createInstance(...params: ConstructorParameters<typeof ProductModelRepo>): Promise<ProductModelRepo>;
395
- }
396
391
  export type Project = ProjectRepo;
397
392
  export declare namespace Project {
398
393
  function createInstance(...params: ConstructorParameters<typeof ProjectRepo>): Promise<ProjectRepo>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
- exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductModel = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = void 0;
4
+ exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = void 0;
5
5
  var AcceptedOffer;
6
6
  (function (AcceptedOffer) {
7
7
  let repo;
@@ -777,17 +777,6 @@ var ProductHasOfferCatalog;
777
777
  }
778
778
  ProductHasOfferCatalog.createInstance = createInstance;
779
779
  })(ProductHasOfferCatalog || (exports.ProductHasOfferCatalog = ProductHasOfferCatalog = {}));
780
- var ProductModel;
781
- (function (ProductModel) {
782
- let repo;
783
- async function createInstance(...params) {
784
- if (repo === undefined) {
785
- repo = (await import('./repo/productModel.js')).ProductModelRepo;
786
- }
787
- return new repo(...params);
788
- }
789
- ProductModel.createInstance = createInstance;
790
- })(ProductModel || (exports.ProductModel = ProductModel = {}));
791
780
  var Project;
792
781
  (function (Project) {
793
782
  let repo;
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "24.0.0"
94
+ "version": "24.1.0-alpha.0"
95
95
  }