@chevre/domain 21.18.0-alpha.31 → 21.18.0-alpha.33
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/example/src/chevre/offerCatalog2offerCatalogItem.ts +4 -0
- package/example/src/chevre/upsertMoviesByIdentifier.ts +5 -4
- package/example/src/chevre/upsertScreeningEventSeriesByVersion.ts +7 -44
- package/lib/chevre/repo/creativeWork.d.ts +12 -2
- package/lib/chevre/repo/creativeWork.js +30 -15
- package/lib/chevre/repo/event.d.ts +5 -2
- package/lib/chevre/repo/event.js +29 -24
- package/lib/chevre/service/event.js +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ async function main() {
|
|
|
21
21
|
let i = 0;
|
|
22
22
|
let maxOfferCatalogItemNumItemListElement = 0;
|
|
23
23
|
let maxIdentifierLength = 0;
|
|
24
|
+
let maxOfferCatalogItemLength = 0;
|
|
24
25
|
for (const offerCatalog of offerCatalogs) {
|
|
25
26
|
i += 1;
|
|
26
27
|
maxIdentifierLength = Math.max(maxIdentifierLength, offerCatalog.identifier.length);
|
|
@@ -145,11 +146,14 @@ async function main() {
|
|
|
145
146
|
maxOfferCatalogItemNumItemListElement =
|
|
146
147
|
Math.max(maxOfferCatalogItemNumItemListElement, offerCatalogItem.itemListElement.length);
|
|
147
148
|
});
|
|
149
|
+
|
|
150
|
+
maxOfferCatalogItemLength = Math.max(maxOfferCatalogItemLength, offerCatalogItems.length);
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
console.log(i, 'offerCatalogs checked');
|
|
151
154
|
console.log('maxOfferCatalogItemNumItemListElement:', maxOfferCatalogItemNumItemListElement);
|
|
152
155
|
console.log('maxIdentifierLength:', maxIdentifierLength);
|
|
156
|
+
console.log('maxOfferCatalogItemLength:', maxOfferCatalogItemLength);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
main()
|
|
@@ -14,9 +14,9 @@ async function main() {
|
|
|
14
14
|
const result = await creativeWorkRepo.upsertMoviesByIdentifier(
|
|
15
15
|
[
|
|
16
16
|
{
|
|
17
|
-
|
|
17
|
+
$set: {
|
|
18
18
|
id: '',
|
|
19
|
-
identifier: '
|
|
19
|
+
identifier: '20231215',
|
|
20
20
|
typeOf: chevre.factory.creativeWorkType.Movie,
|
|
21
21
|
duration: 'PT2H',
|
|
22
22
|
name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
|
|
@@ -34,7 +34,7 @@ async function main() {
|
|
|
34
34
|
value: 'https://iwiz-movies.c.yimg.jp/c/movies/pict/p/p/90/cb/174755_02.jpg'
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
|
-
headline: '
|
|
37
|
+
// headline: 'サブタイトルサブタイトル',
|
|
38
38
|
datePublished: moment('2018-11-04T15:00:00.000Z')
|
|
39
39
|
.toDate(),
|
|
40
40
|
distributor: {
|
|
@@ -44,7 +44,8 @@ async function main() {
|
|
|
44
44
|
distributorType: '001'
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
$unset: { headline: 1 }
|
|
48
49
|
}
|
|
49
50
|
],
|
|
50
51
|
{ replace: true }
|
|
@@ -15,7 +15,7 @@ async function main() {
|
|
|
15
15
|
const result = await eventRepo.upsertScreeningEventSeriesByVersion(
|
|
16
16
|
[
|
|
17
17
|
{
|
|
18
|
-
|
|
18
|
+
$set: {
|
|
19
19
|
eventStatus: chevre.factory.eventStatusType.EventScheduled,
|
|
20
20
|
videoFormat: [],
|
|
21
21
|
soundFormat: [],
|
|
@@ -50,50 +50,13 @@ async function main() {
|
|
|
50
50
|
duration: 'PT1H29M',
|
|
51
51
|
version: '2'
|
|
52
52
|
},
|
|
53
|
-
organizer: { id: '59d20831e53ebc2b4e774466' }
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
attributes: {
|
|
58
|
-
eventStatus: chevre.factory.eventStatusType.EventScheduled,
|
|
59
|
-
videoFormat: [],
|
|
60
|
-
soundFormat: [],
|
|
61
|
-
kanaName: '',
|
|
62
|
-
startDate: moment('2023-12-08T15:00:00Z')
|
|
63
|
-
.toDate(),
|
|
64
|
-
endDate: moment('2123-12-08T15:00:00Z')
|
|
65
|
-
.toDate(),
|
|
66
|
-
typeOf: chevre.factory.eventType.ScreeningEventSeries,
|
|
67
|
-
duration: 'PT2H',
|
|
68
|
-
name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
|
|
69
|
-
offers: {
|
|
70
|
-
typeOf: chevre.factory.offerType.Offer
|
|
71
|
-
},
|
|
72
|
-
project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
|
|
73
|
-
additionalProperty: [
|
|
74
|
-
],
|
|
75
|
-
location: {
|
|
76
|
-
branchCode: '118',
|
|
77
|
-
id: '5bfb841d5a78d7948369979a',
|
|
78
|
-
kanaName: 'シネモーションアカサカ',
|
|
79
|
-
name: { ja: 'シネモーション赤坂 ', en: 'CineMotion Akasaka' },
|
|
80
|
-
typeOf: chevre.factory.placeType.MovieTheater
|
|
81
|
-
},
|
|
82
|
-
workPerformed: {
|
|
83
|
-
typeOf: chevre.factory.creativeWorkType.Movie,
|
|
84
|
-
id: '5bfb841d5a78d79483699801',
|
|
85
|
-
identifier: '071953',
|
|
86
|
-
name: {
|
|
87
|
-
ja: '男はつらいよ 純情篇'
|
|
88
|
-
},
|
|
89
|
-
duration: 'PT1H29M',
|
|
90
|
-
version: '3'
|
|
91
|
-
},
|
|
92
|
-
organizer: { id: '59d20831e53ebc2b4e774466' }
|
|
93
|
-
}
|
|
53
|
+
organizer: { id: '59d20831e53ebc2b4e774466' },
|
|
54
|
+
headline: { ja: 'xxx', en: '' }
|
|
55
|
+
},
|
|
56
|
+
$unset: {}
|
|
94
57
|
},
|
|
95
58
|
{
|
|
96
|
-
|
|
59
|
+
$set: {
|
|
97
60
|
eventStatus: chevre.factory.eventStatusType.EventScheduled,
|
|
98
61
|
videoFormat: [],
|
|
99
62
|
soundFormat: [],
|
|
@@ -126,7 +89,7 @@ async function main() {
|
|
|
126
89
|
ja: '男はつらいよ 純情篇'
|
|
127
90
|
},
|
|
128
91
|
duration: 'PT1H29M',
|
|
129
|
-
version: '
|
|
92
|
+
version: '6'
|
|
130
93
|
},
|
|
131
94
|
organizer: { id: '59d20831e53ebc2b4e774466' }
|
|
132
95
|
}
|
|
@@ -36,12 +36,22 @@ export declare class MongoRepository {
|
|
|
36
36
|
/**
|
|
37
37
|
* コンテンツを保管する
|
|
38
38
|
*/
|
|
39
|
-
saveMovie(params: factory.creativeWork.movie.ICreativeWork
|
|
39
|
+
saveMovie(params: factory.creativeWork.movie.ICreativeWork & {
|
|
40
|
+
/**
|
|
41
|
+
* ドキュメント作成時には無視される
|
|
42
|
+
*/
|
|
43
|
+
$unset?: {
|
|
44
|
+
[key in keyof factory.creativeWork.movie.ICreativeWork]?: 1;
|
|
45
|
+
};
|
|
46
|
+
}): Promise<any>;
|
|
40
47
|
/**
|
|
41
48
|
* コードをキーにして冪等作成
|
|
42
49
|
*/
|
|
43
50
|
upsertMoviesByIdentifier(params: {
|
|
44
|
-
|
|
51
|
+
$set: factory.creativeWork.movie.ICreativeWork;
|
|
52
|
+
$unset?: {
|
|
53
|
+
[key in keyof factory.creativeWork.movie.ICreativeWork]?: 1;
|
|
54
|
+
};
|
|
45
55
|
}[], options?: {
|
|
46
56
|
replace?: boolean;
|
|
47
57
|
}): Promise<{
|
|
@@ -121,12 +121,13 @@ class MongoRepository {
|
|
|
121
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
122
|
let doc;
|
|
123
123
|
if (params.id === '') {
|
|
124
|
-
|
|
124
|
+
const { $unset } = params, createParams = __rest(params, ["$unset"]);
|
|
125
|
+
doc = yield this.creativeWorkModel.create(createParams);
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
|
-
// 上書き禁止属性を除外
|
|
128
|
-
const { id, identifier, project, typeOf } = params,
|
|
129
|
-
doc = yield this.creativeWorkModel.findOneAndUpdate({ _id: { $eq: params.id } },
|
|
128
|
+
// 上書き禁止属性を除外
|
|
129
|
+
const { id, identifier, project, typeOf, $unset } = params, setFields = __rest(params, ["id", "identifier", "project", "typeOf", "$unset"]);
|
|
130
|
+
doc = yield this.creativeWorkModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: setFields }, ($unset !== undefined) ? { $unset } : undefined), { upsert: false, new: true })
|
|
130
131
|
.exec();
|
|
131
132
|
}
|
|
132
133
|
if (doc === null) {
|
|
@@ -143,28 +144,42 @@ class MongoRepository {
|
|
|
143
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
145
|
const bulkWriteOps = [];
|
|
145
146
|
if (Array.isArray(params)) {
|
|
146
|
-
|
|
147
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
148
|
+
params.forEach(({ $set, $unset }) => {
|
|
147
149
|
// リソースのユニークネスを保証するfilter
|
|
148
150
|
const filter = {
|
|
149
|
-
typeOf:
|
|
150
|
-
'project.id': { $eq:
|
|
151
|
-
identifier: { $eq:
|
|
151
|
+
typeOf: $set.typeOf,
|
|
152
|
+
'project.id': { $eq: $set.project.id },
|
|
153
|
+
identifier: { $eq: $set.identifier }
|
|
152
154
|
};
|
|
153
155
|
if ((options === null || options === void 0 ? void 0 : options.replace) === true) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
// updateOneで再実装
|
|
157
|
+
// const replacement: WithoutId<factory.creativeWork.movie.ICreativeWork> = replaceFields;
|
|
158
|
+
// const replaceOne: ReplaceOneModel<factory.creativeWork.movie.ICreativeWork> = {
|
|
159
|
+
// filter,
|
|
160
|
+
// replacement,
|
|
161
|
+
// upsert: true
|
|
162
|
+
// };
|
|
163
|
+
// bulkWriteOps.push({ replaceOne });
|
|
164
|
+
const { id, identifier, project, typeOf } = $set, setFields = __rest($set, ["id", "identifier", "project", "typeOf"]);
|
|
165
|
+
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
156
166
|
throw new factory.errors.ArgumentNull('identifier');
|
|
157
167
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
168
|
+
const setOnInsert = {
|
|
169
|
+
typeOf,
|
|
170
|
+
project,
|
|
171
|
+
identifier
|
|
172
|
+
};
|
|
173
|
+
const updateFilter = Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined);
|
|
174
|
+
const updateOne = {
|
|
160
175
|
filter,
|
|
161
|
-
|
|
176
|
+
update: updateFilter,
|
|
162
177
|
upsert: true
|
|
163
178
|
};
|
|
164
|
-
bulkWriteOps.push({
|
|
179
|
+
bulkWriteOps.push({ updateOne });
|
|
165
180
|
}
|
|
166
181
|
else {
|
|
167
|
-
const { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } =
|
|
182
|
+
const { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = $set, setOnInsertFields = __rest($set, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
|
|
168
183
|
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
169
184
|
throw new factory.errors.ArgumentNull('identifier');
|
|
170
185
|
}
|
|
@@ -123,10 +123,10 @@ export declare class MongoRepository {
|
|
|
123
123
|
* コンテンツ+バージョンをキーにして冪等置換
|
|
124
124
|
*/
|
|
125
125
|
upsertScreeningEventSeriesByVersion(params: {
|
|
126
|
-
|
|
126
|
+
$set: factory.event.IAttributes<factory.eventType.ScreeningEventSeries>;
|
|
127
|
+
$unset?: IUnset<factory.eventType.ScreeningEventSeries>;
|
|
127
128
|
}[]): Promise<{
|
|
128
129
|
bulkWriteResult4insert: BulkWriteResult;
|
|
129
|
-
bulkWriteResult: BulkWriteResult;
|
|
130
130
|
modifiedEvents: {
|
|
131
131
|
id: string;
|
|
132
132
|
}[];
|
|
@@ -147,6 +147,9 @@ export declare class MongoRepository {
|
|
|
147
147
|
save<T extends factory.eventType>(params: {
|
|
148
148
|
id?: string;
|
|
149
149
|
attributes: factory.event.IAttributes<T>;
|
|
150
|
+
/**
|
|
151
|
+
* ドキュメント作成時には無視される
|
|
152
|
+
*/
|
|
150
153
|
$unset?: IUnset<T>;
|
|
151
154
|
upsert?: boolean;
|
|
152
155
|
}): Promise<factory.event.IEvent<T>>;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -615,54 +615,59 @@ class MongoRepository {
|
|
|
615
615
|
) {
|
|
616
616
|
return __awaiter(this, void 0, void 0, function* () {
|
|
617
617
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
618
|
-
// replaceOneでは_idを指定できないので、updateOne(setOnInsert)->replaceOneの2段階でbulkWriteを実行する
|
|
619
618
|
const bulkWriteOps4insert = [];
|
|
620
|
-
const bulkWriteOps = [];
|
|
619
|
+
// const bulkWriteOps: AnyBulkWriteOperation<factory.event.IAttributes<factory.eventType.ScreeningEventSeries>>[] = [];
|
|
621
620
|
const queryFilters = [];
|
|
622
621
|
if (Array.isArray(params)) {
|
|
623
|
-
params.forEach(({
|
|
624
|
-
const version =
|
|
622
|
+
params.forEach(({ $set, $unset }) => {
|
|
623
|
+
const version = $set.workPerformed.version;
|
|
625
624
|
if (typeof version !== 'string' || version.length === 0) {
|
|
626
625
|
throw new factory.errors.ArgumentNull('workPerformed.version');
|
|
627
626
|
}
|
|
628
627
|
// リソースのユニークネスを保証するfilter
|
|
629
628
|
const filter = {
|
|
630
|
-
typeOf:
|
|
631
|
-
'project.id': { $eq:
|
|
632
|
-
'location.branchCode': { $exists: true, $eq:
|
|
633
|
-
'workPerformed.identifier': { $exists: true, $eq:
|
|
629
|
+
typeOf: $set.typeOf,
|
|
630
|
+
'project.id': { $eq: $set.project.id },
|
|
631
|
+
'location.branchCode': { $exists: true, $eq: $set.location.branchCode },
|
|
632
|
+
'workPerformed.identifier': { $exists: true, $eq: $set.workPerformed.identifier },
|
|
634
633
|
'workPerformed.version': { $exists: true, $eq: version }
|
|
635
634
|
};
|
|
636
635
|
queryFilters.push({
|
|
637
|
-
typeOf:
|
|
638
|
-
'project.id': { $eq:
|
|
639
|
-
'location.branchCode': { $exists: true, $eq:
|
|
640
|
-
'workPerformed.identifier': { $exists: true, $eq:
|
|
636
|
+
typeOf: $set.typeOf,
|
|
637
|
+
'project.id': { $eq: $set.project.id },
|
|
638
|
+
'location.branchCode': { $exists: true, $eq: $set.location.branchCode },
|
|
639
|
+
'workPerformed.identifier': { $exists: true, $eq: $set.workPerformed.identifier },
|
|
641
640
|
'workPerformed.version': { $exists: true, $eq: version }
|
|
642
641
|
});
|
|
643
|
-
const
|
|
642
|
+
const { identifier, project, typeOf } = $set, setFields = __rest($set, ["identifier", "project", "typeOf"]);
|
|
643
|
+
const setOnInsert = {
|
|
644
|
+
project,
|
|
645
|
+
typeOf,
|
|
646
|
+
_id: uniqid()
|
|
647
|
+
};
|
|
644
648
|
const updateOne = {
|
|
645
649
|
filter,
|
|
646
|
-
update: { $setOnInsert: setOnInsert },
|
|
650
|
+
update: Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined),
|
|
647
651
|
upsert: true
|
|
648
652
|
};
|
|
649
653
|
bulkWriteOps4insert.push({ updateOne });
|
|
650
|
-
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
654
|
+
// updateOneで再実装
|
|
655
|
+
// const replacement: WithoutId<factory.event.IAttributes<factory.eventType.ScreeningEventSeries>> = attributes;
|
|
656
|
+
// const replaceOne: ReplaceOneModel<factory.event.IAttributes<factory.eventType.ScreeningEventSeries>> = {
|
|
657
|
+
// filter,
|
|
658
|
+
// replacement,
|
|
659
|
+
// upsert: true
|
|
660
|
+
// };
|
|
661
|
+
// bulkWriteOps.push({ replaceOne });
|
|
657
662
|
});
|
|
658
663
|
}
|
|
659
|
-
if (
|
|
664
|
+
if (bulkWriteOps4insert.length > 0) {
|
|
660
665
|
const bulkWriteResult4insert = yield this.eventModel.bulkWrite(bulkWriteOps4insert, { ordered: false });
|
|
661
|
-
const bulkWriteResult =
|
|
666
|
+
// const bulkWriteResult = await this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
662
667
|
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
663
668
|
const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, { _id: 1 })
|
|
664
669
|
.exec();
|
|
665
|
-
return { bulkWriteResult4insert,
|
|
670
|
+
return { bulkWriteResult4insert, modifiedEvents };
|
|
666
671
|
}
|
|
667
672
|
});
|
|
668
673
|
}
|
|
@@ -278,7 +278,7 @@ function saveScreeningEventSeries(params) {
|
|
|
278
278
|
yield repos.creativeWork.upsertMoviesByIdentifier(saveParams.map((saveScreeningEventSeriesParams) => {
|
|
279
279
|
var _a;
|
|
280
280
|
return {
|
|
281
|
-
|
|
281
|
+
$set: Object.assign(Object.assign({ typeOf: factory.creativeWorkType.Movie, project: params.project, identifier: saveScreeningEventSeriesParams.attributes.workPerformed.identifier, name: { ja: (_a = saveScreeningEventSeriesParams.attributes.workPerformed.name) === null || _a === void 0 ? void 0 : _a.ja }, offers: { typeOf: factory.offerType.Offer } }, (typeof saveScreeningEventSeriesParams.attributes.workPerformed.contentRating === 'string')
|
|
282
282
|
? { contentRating: saveScreeningEventSeriesParams.attributes.workPerformed.contentRating }
|
|
283
283
|
: undefined), (typeof saveScreeningEventSeriesParams.attributes.workPerformed.duration === 'string')
|
|
284
284
|
? { duration: saveScreeningEventSeriesParams.attributes.workPerformed.duration }
|
package/package.json
CHANGED