@chevre/domain 21.18.0-alpha.2 → 21.18.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,57 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ const PROJECT_ID = String(process.env.PROJECT_ID);
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const creativeWorkRepo = await chevre.repository.CreativeWork.createInstance(mongoose.connection);
13
+
14
+ const result = await creativeWorkRepo.upsertMoviesByIdentifier(
15
+ [
16
+ {
17
+ attributes: {
18
+ id: '',
19
+ identifier: '00001',
20
+ typeOf: chevre.factory.creativeWorkType.Movie,
21
+ duration: 'PT2H',
22
+ name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
23
+ offers: {
24
+ typeOf: chevre.factory.offerType.Offer,
25
+ availabilityEnds: moment('2118-11-04T15:00:00.000Z')
26
+ .toDate(),
27
+ availabilityStarts: moment('2018-11-25T15:00:00.000Z')
28
+ .toDate()
29
+ },
30
+ project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
31
+ additionalProperty: [
32
+ {
33
+ name: 'posterImage',
34
+ value: 'https://iwiz-movies.c.yimg.jp/c/movies/pict/p/p/90/cb/174755_02.jpg'
35
+ }
36
+ ],
37
+ headline: 'サブタイトルサブタイトルサブタイトル',
38
+ datePublished: moment('2018-11-04T15:00:00.000Z')
39
+ .toDate(),
40
+ distributor: {
41
+ id: '5e35398a8067a30012dd6717',
42
+ codeValue: '001',
43
+ ...{
44
+ distributorType: '001'
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ],
50
+ { replace: true }
51
+ );
52
+ console.log('result:', result);
53
+ }
54
+
55
+ main()
56
+ .then(console.log)
57
+ .catch(console.error);
@@ -0,0 +1,22 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+
4
+ const MINUTES = 10;
5
+
6
+ async function main() {
7
+ const duration = moment.duration(MINUTES, 'minutes');
8
+ const newDuration = moment.duration(duration.toISOString());
9
+ console.log(duration);
10
+ console.log(newDuration);
11
+ console.log(duration.toISOString());
12
+ console.log(newDuration.toISOString());
13
+ console.log(newDuration.isValid());
14
+ console.log(moment.duration('invalid')
15
+ .isValid());
16
+ }
17
+
18
+ main()
19
+ .then(() => {
20
+ console.log('success!');
21
+ })
22
+ .catch(console.error);
@@ -42,7 +42,11 @@ export declare class MongoRepository {
42
42
  */
43
43
  upsertMoviesByIdentifier(params: {
44
44
  attributes: factory.creativeWork.movie.ICreativeWork;
45
- }[]): Promise<BulkWriteResult | void>;
45
+ }[], options?: {
46
+ replace?: boolean;
47
+ }): Promise<{
48
+ bulkWriteResult: BulkWriteResult;
49
+ } | void>;
46
50
  /**
47
51
  * コンテンツを検索する
48
52
  */
@@ -138,36 +138,57 @@ class MongoRepository {
138
138
  /**
139
139
  * コードをキーにして冪等作成
140
140
  */
141
- upsertMoviesByIdentifier(params) {
141
+ // tslint:disable-next-line:max-func-body-length
142
+ upsertMoviesByIdentifier(params, options) {
142
143
  return __awaiter(this, void 0, void 0, function* () {
143
144
  const bulkWriteOps = [];
144
145
  if (Array.isArray(params)) {
145
146
  params.forEach((creatingMovieParams) => {
146
- const _a = creatingMovieParams.attributes, { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = _a, setOnInsertFields = __rest(_a, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
147
- if (typeof identifier !== 'string' || identifier.length === 0) {
148
- throw new factory.errors.ArgumentNull('identifier');
147
+ if ((options === null || options === void 0 ? void 0 : options.replace) === true) {
148
+ const _a = creatingMovieParams.attributes, { id } = _a, replaceFields = __rest(_a, ["id"]);
149
+ if (typeof replaceFields.identifier !== 'string' || replaceFields.identifier.length === 0) {
150
+ throw new factory.errors.ArgumentNull('identifier');
151
+ }
152
+ const replacement = replaceFields;
153
+ const replaceOne = {
154
+ filter: {
155
+ typeOf: replaceFields.typeOf,
156
+ 'project.id': { $eq: replaceFields.project.id },
157
+ identifier: { $eq: replaceFields.identifier }
158
+ },
159
+ replacement,
160
+ upsert: true
161
+ };
162
+ bulkWriteOps.push({ replaceOne });
163
+ }
164
+ else {
165
+ const _b = creatingMovieParams.attributes, { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = _b, setOnInsertFields = __rest(_b, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
166
+ if (typeof identifier !== 'string' || identifier.length === 0) {
167
+ throw new factory.errors.ArgumentNull('identifier');
168
+ }
169
+ const updateFilter = {
170
+ $setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
171
+ project,
172
+ identifier }),
173
+ // 変更可能な属性のみ上書き
174
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
175
+ };
176
+ const updateOne = {
177
+ filter: {
178
+ typeOf: typeOf,
179
+ 'project.id': { $eq: project.id },
180
+ identifier: { $eq: identifier }
181
+ },
182
+ update: updateFilter,
183
+ upsert: true
184
+ };
185
+ bulkWriteOps.push({ updateOne });
149
186
  }
150
- const updateFilter = {
151
- $setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
152
- project,
153
- identifier }),
154
- // 変更可能な属性のみ上書き
155
- $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
156
- };
157
- const updateOne = {
158
- filter: {
159
- typeOf: typeOf,
160
- 'project.id': { $eq: project.id },
161
- identifier: { $eq: identifier }
162
- },
163
- update: updateFilter,
164
- upsert: true
165
- };
166
- bulkWriteOps.push({ updateOne });
167
187
  });
168
188
  }
169
189
  if (bulkWriteOps.length > 0) {
170
- return this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
190
+ const bulkWriteResult = yield this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
191
+ return { bulkWriteResult };
171
192
  }
172
193
  });
173
194
  }
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.18.0-alpha.2"
118
+ "version": "21.18.0-alpha.3"
119
119
  }