@chevre/domain 23.0.0-alpha.4 → 23.0.0-alpha.5

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,34 @@
1
+ // tslint:disable:no-console no-magic-numbers
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
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const noteRepo = await chevre.repository.Note.createInstance(mongoose.connection);
13
+ const notes = await noteRepo.findNotes(
14
+ {
15
+ limit: 10,
16
+ page: 1,
17
+ project: { id: { $eq: project.id } },
18
+ hasDigitalDocumentPermission: {
19
+ grantee: {
20
+ audienceType: {
21
+ $eq: chevre.factory.creativeWork.noteDigitalDocument.PermissionGranteeAudienceType.Public
22
+ }
23
+ }
24
+ }
25
+ },
26
+ ['about', 'identifier']
27
+ );
28
+ // tslint:disable-next-line:no-null-keyword
29
+ console.dir(notes, { depth: null });
30
+ }
31
+
32
+ main()
33
+ .then()
34
+ .catch(console.error);
@@ -27,14 +27,13 @@ async function main() {
27
27
  };
28
28
  const createResult = await noteRepo.upsertNotesByIdentifier(
29
29
  [
30
- {
31
- $set: creatingNote
32
- // $unset: {}
33
- },
34
30
  {
35
31
  $set: creatingNote
36
32
  // $unset: {}
37
33
  }
34
+ // {
35
+ // $set: creatingNote
36
+ // }
38
37
  ],
39
38
  { update: false }
40
39
  );
@@ -46,6 +45,9 @@ async function main() {
46
45
  {
47
46
  $set: creatingNote
48
47
  }
48
+ // {
49
+ // $set: creatingNote
50
+ // }
49
51
  ],
50
52
  { update: true }
51
53
  );
@@ -85,6 +85,15 @@ const indexes = [
85
85
  [
86
86
  { identifier: 1, dateCreated: -1 },
87
87
  { name: 'identifier' }
88
+ ],
89
+ [
90
+ { 'hasDigitalDocumentPermission.grantee.audienceType': 1, dateCreated: -1 },
91
+ {
92
+ name: 'permissionGranteeAudienceType',
93
+ partialFilterExpression: {
94
+ 'hasDigitalDocumentPermission.grantee.audienceType': { $exists: true }
95
+ }
96
+ }
88
97
  ]
89
98
  // discontinue(2025-05-08~)
90
99
  // [
@@ -15,6 +15,8 @@ export declare class NoteRepo {
15
15
  })[]>;
16
16
  /**
17
17
  * メモ識別子をキーにして冪等置換
18
+ * 主題+識別子でユニーク必須
19
+ * 編集の場合、存在検証される
18
20
  */
19
21
  upsertNotesByIdentifier(params: {
20
22
  $set: Pick<INoteDigitalDocument, 'about' | 'creator' | 'identifier' | 'project' | 'provider' | 'text' | 'version' | 'hasDigitalDocumentPermission'> & {
@@ -32,15 +34,6 @@ export declare class NoteRepo {
32
34
  id: string;
33
35
  }[];
34
36
  } | void>;
35
- /**
36
- * 既知のメモIDリストからメモを削除する
37
- */
38
- deleteNotesByIds(params: {
39
- project: {
40
- id: string;
41
- };
42
- ids: string[];
43
- }): Promise<DeleteResult | void>;
44
37
  /**
45
38
  * 主題リソースから全メモを削除する
46
39
  */
@@ -35,7 +35,7 @@ class NoteRepo {
35
35
  this.noteModel = connection.model(note_1.modelName, (0, note_1.createSchema)());
36
36
  }
37
37
  static CREATE_MONGO_CONDITIONS(params) {
38
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
39
39
  const andConditions = [];
40
40
  const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
41
41
  if (Array.isArray(idIn)) {
@@ -77,6 +77,10 @@ class NoteRepo {
77
77
  if (Array.isArray(identifierIn)) {
78
78
  andConditions.push({ identifier: { $in: identifierIn } });
79
79
  }
80
+ const audienceTypeEq = (_v = (_u = (_t = params.hasDigitalDocumentPermission) === null || _t === void 0 ? void 0 : _t.grantee) === null || _u === void 0 ? void 0 : _u.audienceType) === null || _v === void 0 ? void 0 : _v.$eq;
81
+ if (typeof audienceTypeEq === 'string') {
82
+ andConditions.push({ 'hasDigitalDocumentPermission.grantee.audienceType': { $exists: true, $eq: audienceTypeEq } });
83
+ }
80
84
  return andConditions;
81
85
  }
82
86
  findNotes(params, inclusion) {
@@ -107,25 +111,33 @@ class NoteRepo {
107
111
  }
108
112
  /**
109
113
  * メモ識別子をキーにして冪等置換
114
+ * 主題+識別子でユニーク必須
115
+ * 編集の場合、存在検証される
110
116
  */
117
+ // tslint:disable-next-line:max-func-body-length
111
118
  upsertNotesByIdentifier(params, options) {
112
119
  return __awaiter(this, void 0, void 0, function* () {
113
120
  const now = new Date();
114
121
  const { update } = options;
115
122
  const bulkWriteOps = [];
116
123
  const queryFilters = [];
124
+ let uniqueIdentifiers = [];
117
125
  if (Array.isArray(params)) {
118
126
  params.forEach(({ $set }) => {
119
127
  const { about, creator, identifier, project, provider, text, version, hasDigitalDocumentPermission } = $set;
120
- if (typeof identifier !== 'string' || identifier.length === 0) {
128
+ if (typeof about.id !== 'string' || about.id === '') {
129
+ throw new factory.errors.ArgumentNull('about.id');
130
+ }
131
+ if (typeof identifier !== 'string' || identifier === '') {
121
132
  throw new factory.errors.ArgumentNull('identifier');
122
133
  }
123
- if (typeof version !== 'string' || version.length === 0) {
134
+ if (typeof version !== 'string' || version === '') {
124
135
  throw new factory.errors.ArgumentNull('version');
125
136
  }
126
137
  if (typeof text !== 'string') {
127
138
  throw new factory.errors.ArgumentNull('text');
128
139
  }
140
+ uniqueIdentifiers.push(`${about.id}:${identifier}`);
129
141
  // リソースのユニークネスを保証するfilter
130
142
  const filter = {
131
143
  'project.id': { $eq: project.id },
@@ -167,6 +179,25 @@ class NoteRepo {
167
179
  });
168
180
  }
169
181
  if (bulkWriteOps.length > 0) {
182
+ // 主題+識別子でユニーク検証
183
+ uniqueIdentifiers = [...new Set(uniqueIdentifiers)];
184
+ if (uniqueIdentifiers.length !== bulkWriteOps.length) {
185
+ throw new factory.errors.Argument('identifier', '(about.id + identifier)s must be unique');
186
+ }
187
+ if (update === true) {
188
+ // 編集の場合、存在検証
189
+ const modifyingNotes = yield this.noteModel.find({ $or: queryFilters }, {
190
+ _id: 0,
191
+ id: { $toString: '$_id' }
192
+ })
193
+ .lean()
194
+ .exec();
195
+ // tslint:disable-next-line:no-console
196
+ console.log('NoteRepo.upsertNotesByIdentifier:', params.length, 'params ->', modifyingNotes.length, 'modifyingNotes found.', JSON.stringify(modifyingNotes));
197
+ if (modifyingNotes.length !== bulkWriteOps.length) {
198
+ throw new factory.errors.NotFound(factory.creativeWorkType.NoteDigitalDocument);
199
+ }
200
+ }
170
201
  const bulkWriteResult = yield this.noteModel.bulkWrite(bulkWriteOps, { ordered: false });
171
202
  // modifiedの場合upsertedIdsに含まれないので、idを検索する
172
203
  const modifiedNotes = yield this.noteModel.find({ $or: queryFilters }, {
@@ -179,21 +210,24 @@ class NoteRepo {
179
210
  }
180
211
  });
181
212
  }
182
- /**
183
- * 既知のメモIDリストからメモを削除する
184
- */
185
- deleteNotesByIds(params) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- const { project, ids } = params;
188
- if (Array.isArray(ids) && ids.length > 0) {
189
- return this.noteModel.deleteMany({
190
- 'project.id': { $eq: project.id },
191
- _id: { $in: ids }
192
- })
193
- .exec();
194
- }
195
- });
196
- }
213
+ // /**
214
+ // * 既知のメモIDリストからメモを削除する
215
+ // */
216
+ // public async deleteNotesByIds(params: {
217
+ // project: { id: string };
218
+ // ids: string[];
219
+ // }): Promise<DeleteResult | void> {
220
+ // const { project, ids } = params;
221
+ // if (Array.isArray(ids) && ids.length > 0) {
222
+ // return this.noteModel.deleteMany(
223
+ // {
224
+ // 'project.id': { $eq: project.id },
225
+ // _id: { $in: ids }
226
+ // }
227
+ // )
228
+ // .exec();
229
+ // }
230
+ // }
197
231
  /**
198
232
  * 主題リソースから全メモを削除する
199
233
  */
@@ -20,6 +20,7 @@ function verifyOfferedByToken(params) {
20
20
  try {
21
21
  result = yield new Promise((resolve, reject) => {
22
22
  jwt.verify(token, secret, {
23
+ algorithms: ['HS256'],
23
24
  issuer
24
25
  // ...(Array.isArray(params.audience)) ? { audience: params.audience } : undefined
25
26
  }, (err, decoded) => {
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "5.0.0",
15
- "@cinerino/sdk": "12.5.0-alpha.5",
14
+ "@chevre/factory": "5.1.0-alpha.0",
15
+ "@cinerino/sdk": "12.5.0-alpha.6",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.4.0-alpha.1",
18
18
  "@sendgrid/client": "8.1.4",
@@ -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": "23.0.0-alpha.4"
118
+ "version": "23.0.0-alpha.5"
119
119
  }