@chevre/domain 21.21.0-alpha.1 → 21.21.0-alpha.3

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.
@@ -0,0 +1,74 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const noteRepo = await chevre.repository.Note.createInstance(mongoose.connection);
12
+ const result = await noteRepo.search({
13
+ limit: 1,
14
+ page: 1,
15
+ inclusion: ['text', 'about', 'identifier'],
16
+ exclusion: []
17
+ });
18
+ console.log('result:', result);
19
+
20
+ let createResult = await noteRepo.upsertByIdentifier([{
21
+ about: {
22
+ id: '65c41ca61898c4feba427e4f',
23
+ orderNumber: 'CIN2-8393218-6955938',
24
+ typeOf: chevre.factory.order.OrderType.Order
25
+ },
26
+ creator: {
27
+ id: '582ee997-86ac-43e4-90c2-213a10c3282f',
28
+ typeOf: chevre.factory.personType.Person
29
+ },
30
+ identifier: '20240213OrderNote',
31
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
32
+ text: 'note text',
33
+ version: '1'
34
+ }]);
35
+ console.log('createResult:', createResult);
36
+
37
+ createResult = await noteRepo.upsertByIdentifier([{
38
+ about: {
39
+ id: '65c41ca61898c4feba427e4f',
40
+ orderNumber: 'CIN2-8393218-6955938',
41
+ typeOf: chevre.factory.order.OrderType.Order
42
+ },
43
+ creator: {
44
+ id: '582ee997-86ac-43e4-90c2-213a10c3282f',
45
+ typeOf: chevre.factory.personType.Person
46
+ },
47
+ identifier: '20240213OrderNote',
48
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
49
+ text: 'note text updated',
50
+ version: '1'
51
+ }]);
52
+ console.log('createResult:', createResult);
53
+
54
+ createResult = await noteRepo.upsertByIdentifier([{
55
+ about: {
56
+ id: '65c41ca61898c4feba427e4f',
57
+ orderNumber: 'CIN2-8393218-6955938',
58
+ typeOf: chevre.factory.order.OrderType.Order
59
+ },
60
+ creator: {
61
+ id: '582ee997-86ac-43e4-90c2-213a10c3282f',
62
+ typeOf: chevre.factory.personType.Person
63
+ },
64
+ identifier: '20240213OrderNote',
65
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
66
+ text: '',
67
+ version: '1'
68
+ }]);
69
+ console.log('createResult:', createResult);
70
+ }
71
+
72
+ main()
73
+ .then(console.log)
74
+ .catch(console.error);
@@ -0,0 +1,5 @@
1
+ import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
2
+ declare const modelName = "Note";
3
+ declare const indexes: [d: IndexDefinition, o: IndexOptions][];
4
+ declare function createSchema(): Schema;
5
+ export { modelName, indexes, createSchema };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSchema = exports.indexes = exports.modelName = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const writeConcern_1 = require("../writeConcern");
6
+ const settings_1 = require("../../../settings");
7
+ const modelName = 'Note';
8
+ exports.modelName = modelName;
9
+ const schemaDefinition = {
10
+ identifier: {
11
+ type: String,
12
+ required: true
13
+ },
14
+ text: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ project: {
19
+ type: mongoose_1.SchemaTypes.Mixed,
20
+ required: true
21
+ },
22
+ about: {
23
+ type: mongoose_1.SchemaTypes.Mixed,
24
+ required: true
25
+ },
26
+ dateCreated: Date,
27
+ dateModified: Date,
28
+ creator: {
29
+ type: mongoose_1.SchemaTypes.Mixed,
30
+ required: true
31
+ },
32
+ editor: mongoose_1.SchemaTypes.Mixed,
33
+ version: {
34
+ type: String,
35
+ required: true
36
+ },
37
+ typeOf: {
38
+ type: String,
39
+ required: true
40
+ }
41
+ };
42
+ const schemaOptions = {
43
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
44
+ autoCreate: false,
45
+ collection: 'notes',
46
+ id: true,
47
+ read: 'primary',
48
+ writeConcern: writeConcern_1.writeConcern,
49
+ strict: true,
50
+ strictQuery: false,
51
+ timestamps: {
52
+ createdAt: 'createdAt',
53
+ updatedAt: 'updatedAt'
54
+ },
55
+ toJSON: {
56
+ getters: false,
57
+ virtuals: false,
58
+ minimize: false,
59
+ versionKey: false
60
+ },
61
+ toObject: {
62
+ getters: false,
63
+ virtuals: true,
64
+ minimize: false,
65
+ versionKey: false
66
+ }
67
+ };
68
+ const indexes = [
69
+ [
70
+ { createdAt: 1 },
71
+ { name: 'searchByCreatedAt' }
72
+ ],
73
+ [
74
+ { updatedAt: 1 },
75
+ { name: 'searchByUpdatedAt' }
76
+ ]
77
+ ];
78
+ exports.indexes = indexes;
79
+ /**
80
+ * メモスキーマ
81
+ */
82
+ let schema;
83
+ function createSchema() {
84
+ if (schema === undefined) {
85
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
86
+ if (settings_1.MONGO_AUTO_INDEX) {
87
+ indexes.forEach((indexParams) => {
88
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
89
+ });
90
+ }
91
+ }
92
+ return schema;
93
+ }
94
+ exports.createSchema = createSchema;
@@ -0,0 +1,25 @@
1
+ import type { BulkWriteResult } from 'mongodb';
2
+ import type { Connection } from 'mongoose';
3
+ import * as factory from '../factory';
4
+ type INoteDigitalDocument = factory.creativeWork.noteDigitalDocument.INoteDigitalDocument;
5
+ type IKeyOfProjection = keyof INoteDigitalDocument | '_id';
6
+ /**
7
+ * メモリポジトリ
8
+ */
9
+ export declare class MongoRepository {
10
+ private readonly noteModel;
11
+ constructor(connection: Connection);
12
+ static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.noteDigitalDocument.ISearchConditions): any[];
13
+ /**
14
+ * 検索
15
+ */
16
+ search(params: factory.creativeWork.noteDigitalDocument.ISearchConditions & {
17
+ inclusion: IKeyOfProjection[];
18
+ exclusion: IKeyOfProjection[];
19
+ }): Promise<INoteDigitalDocument[]>;
20
+ /**
21
+ * コードをキーにしてなければ作成する(複数対応)
22
+ */
23
+ upsertByIdentifier(params: Pick<INoteDigitalDocument, 'about' | 'creator' | 'identifier' | 'project' | 'text' | 'version'>[]): Promise<BulkWriteResult | void>;
24
+ }
25
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MongoRepository = void 0;
13
+ const note_1 = require("./mongoose/schemas/note");
14
+ const factory = require("../factory");
15
+ const settings_1 = require("../settings");
16
+ /**
17
+ * メモリポジトリ
18
+ */
19
+ class MongoRepository {
20
+ constructor(connection) {
21
+ this.noteModel = connection.model(note_1.modelName, (0, note_1.createSchema)());
22
+ }
23
+ static CREATE_MONGO_CONDITIONS(params) {
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
25
+ const andConditions = [];
26
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
27
+ if (typeof projectIdEq === 'string') {
28
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
29
+ }
30
+ const aboutIdEq = (_d = (_c = params.about) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
31
+ if (typeof aboutIdEq === 'string') {
32
+ andConditions.push({ 'about.id': { $eq: aboutIdEq } });
33
+ }
34
+ const aboutIdIn = (_f = (_e = params.about) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$in;
35
+ if (Array.isArray(aboutIdIn)) {
36
+ andConditions.push({ 'about.id': { $in: aboutIdIn } });
37
+ }
38
+ const aboutOrderNumberEq = (_h = (_g = params.about) === null || _g === void 0 ? void 0 : _g.orderNumber) === null || _h === void 0 ? void 0 : _h.$eq;
39
+ if (typeof aboutOrderNumberEq === 'string') {
40
+ andConditions.push({ 'about.orderNumber': { $exists: true, $eq: aboutOrderNumberEq } });
41
+ }
42
+ const aboutOrderNumberIn = (_k = (_j = params.about) === null || _j === void 0 ? void 0 : _j.orderNumber) === null || _k === void 0 ? void 0 : _k.$in;
43
+ if (Array.isArray(aboutOrderNumberIn)) {
44
+ andConditions.push({ 'about.orderNumber': { $exists: true, $in: aboutOrderNumberIn } });
45
+ }
46
+ const identifierEq = (_l = params.identifier) === null || _l === void 0 ? void 0 : _l.$eq;
47
+ if (typeof identifierEq === 'string') {
48
+ andConditions.push({ identifier: { $eq: identifierEq } });
49
+ }
50
+ return andConditions;
51
+ }
52
+ /**
53
+ * 検索
54
+ */
55
+ search(params) {
56
+ var _a;
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ let projection = {};
59
+ if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
60
+ params.inclusion.forEach((field) => {
61
+ projection[field] = 1;
62
+ });
63
+ }
64
+ else {
65
+ projection = {
66
+ __v: 0,
67
+ createdAt: 0,
68
+ updatedAt: 0
69
+ };
70
+ if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
71
+ params.exclusion.forEach((field) => {
72
+ projection[field] = 0;
73
+ });
74
+ }
75
+ }
76
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
77
+ const query = this.noteModel.find((conditions.length > 0) ? { $and: conditions } : {})
78
+ .select(projection);
79
+ if (typeof params.limit === 'number' && params.limit > 0) {
80
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
81
+ query.limit(params.limit)
82
+ .skip(params.limit * (page - 1));
83
+ }
84
+ // tslint:disable-next-line:no-single-line-block-comment
85
+ /* istanbul ignore else */
86
+ if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.dateCreated) !== undefined) {
87
+ query.sort({ dateCreated: params.sort.dateCreated });
88
+ }
89
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
90
+ .exec()
91
+ .then((docs) => docs.map((doc) => doc.toObject()));
92
+ });
93
+ }
94
+ // public async create(params: Pick<
95
+ // INoteDigitalDocument,
96
+ // 'about' | 'creator' | 'identifier' | 'project' | 'text' | 'version'
97
+ // >): Promise<INoteDigitalDocument> {
98
+ // const { about, creator, identifier, project, text, version } = params;
99
+ // const creatingDoc: INoteDigitalDocument = {
100
+ // about, creator, identifier, project, text, version,
101
+ // dateCreated: new Date(),
102
+ // typeOf: factory.creativeWorkType.NoteDigitalDocument
103
+ // };
104
+ // const doc = await this.noteModel.create(creatingDoc);
105
+ // return doc.toObject();
106
+ // }
107
+ /**
108
+ * コードをキーにしてなければ作成する(複数対応)
109
+ */
110
+ upsertByIdentifier(params) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ const now = new Date();
113
+ const bulkWriteOps = [];
114
+ if (Array.isArray(params)) {
115
+ params.forEach((creatingNoteParams) => {
116
+ const { about, creator, identifier, project, text, version } = creatingNoteParams;
117
+ if (typeof identifier !== 'string' || identifier.length === 0) {
118
+ throw new factory.errors.ArgumentNull('identifier');
119
+ }
120
+ if (typeof version !== 'string' || version.length === 0) {
121
+ throw new factory.errors.ArgumentNull('version');
122
+ }
123
+ if (typeof text !== 'string') {
124
+ throw new factory.errors.ArgumentNull('text');
125
+ }
126
+ // リソースのユニークネスを保証するfilter
127
+ const filter = {
128
+ typeOf: { $eq: factory.creativeWorkType.NoteDigitalDocument },
129
+ 'project.id': { $eq: project.id },
130
+ 'about.id': { $eq: about.id },
131
+ identifier: { $eq: identifier },
132
+ version: { $eq: version }
133
+ };
134
+ const setOnInsert = {
135
+ about, creator, identifier, project, version,
136
+ dateCreated: now,
137
+ typeOf: factory.creativeWorkType.NoteDigitalDocument
138
+ };
139
+ // 変更可能な属性のみ上書き
140
+ const setFields = {
141
+ dateModified: now,
142
+ editor: creator,
143
+ text
144
+ };
145
+ const updateFilter = {
146
+ $setOnInsert: setOnInsert,
147
+ $set: setFields
148
+ };
149
+ const updateOne = {
150
+ filter,
151
+ update: updateFilter,
152
+ upsert: true
153
+ };
154
+ bulkWriteOps.push({ updateOne });
155
+ });
156
+ }
157
+ if (bulkWriteOps.length > 0) {
158
+ return this.noteModel.bulkWrite(bulkWriteOps, { ordered: false });
159
+ }
160
+ });
161
+ }
162
+ }
163
+ exports.MongoRepository = MongoRepository;
@@ -20,6 +20,7 @@ import type { MongoRepository as EmailMessageRepo } from './repo/emailMessage';
20
20
  import type { MongoRepository as EventRepo } from './repo/event';
21
21
  import type { MongoRepository as MemberRepo } from './repo/member';
22
22
  import type { MongoRepository as MerchantReturnPolicyRepo } from './repo/merchantReturnPolicy';
23
+ import type { MongoRepository as NoteRepo } from './repo/note';
23
24
  import type { MongoRepository as OfferRepo } from './repo/offer';
24
25
  import type { MongoRepository as OfferCatalogRepo } from './repo/offerCatalog';
25
26
  import type { MongoRepository as OfferCatalogItemRepo } from './repo/offerCatalogItem';
@@ -133,6 +134,10 @@ export type MerchantReturnPolicy = MerchantReturnPolicyRepo;
133
134
  export declare namespace MerchantReturnPolicy {
134
135
  function createInstance(...params: ConstructorParameters<typeof MerchantReturnPolicyRepo>): Promise<MerchantReturnPolicyRepo>;
135
136
  }
137
+ export type Note = NoteRepo;
138
+ export declare namespace Note {
139
+ function createInstance(...params: ConstructorParameters<typeof NoteRepo>): Promise<NoteRepo>;
140
+ }
136
141
  export type OfferCatalog = OfferCatalogRepo;
137
142
  export declare namespace OfferCatalog {
138
143
  function createInstance(...params: ConstructorParameters<typeof OfferCatalogRepo>): Promise<OfferCatalogRepo>;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerPaymentAccepted = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.ProductOffer = exports.Product = exports.PriceSpecification = exports.place = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
- exports.rateLimit = exports.Trip = void 0;
12
+ exports.Transaction = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerPaymentAccepted = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.ProductOffer = exports.Product = exports.PriceSpecification = exports.place = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
+ exports.rateLimit = exports.Trip = exports.TransactionNumber = void 0;
14
14
  var AcceptedOffer;
15
15
  (function (AcceptedOffer) {
16
16
  let repo;
@@ -271,6 +271,19 @@ var MerchantReturnPolicy;
271
271
  }
272
272
  MerchantReturnPolicy.createInstance = createInstance;
273
273
  })(MerchantReturnPolicy = exports.MerchantReturnPolicy || (exports.MerchantReturnPolicy = {}));
274
+ var Note;
275
+ (function (Note) {
276
+ let repo;
277
+ function createInstance(...params) {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ if (repo === undefined) {
280
+ repo = (yield Promise.resolve().then(() => require('./repo/note'))).MongoRepository;
281
+ }
282
+ return new repo(...params);
283
+ });
284
+ }
285
+ Note.createInstance = createInstance;
286
+ })(Note = exports.Note || (exports.Note = {}));
274
287
  var OfferCatalog;
275
288
  (function (OfferCatalog) {
276
289
  let repo;
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.353.0",
14
- "@cinerino/sdk": "5.11.0-alpha.1",
13
+ "@chevre/factory": "4.354.0-alpha.0",
14
+ "@cinerino/sdk": "5.11.0-alpha.2",
15
15
  "@motionpicture/coa-service": "9.3.0-alpha.5",
16
16
  "@motionpicture/gmo-service": "5.3.0-alpha.4",
17
17
  "@sendgrid/mail": "6.4.0",
@@ -111,5 +111,5 @@
111
111
  "postversion": "git push origin --tags",
112
112
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
113
113
  },
114
- "version": "21.21.0-alpha.1"
114
+ "version": "21.21.0-alpha.3"
115
115
  }