@chevre/domain 23.0.0-alpha.4 → 23.0.0-alpha.6
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/note/findNotes.ts +34 -0
- package/example/src/chevre/note/upsertNotesByIdentifier.ts +6 -4
- package/lib/chevre/repo/mongoose/schemas/note.js +9 -0
- package/lib/chevre/repo/mongoose/schemas/product.d.ts +1 -1
- package/lib/chevre/repo/note.d.ts +2 -9
- package/lib/chevre/repo/note.js +52 -18
- package/lib/chevre/repo/product.js +15 -14
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -0
- package/package.json +3 -3
|
@@ -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
|
// [
|
|
@@ -2,7 +2,7 @@ import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from '
|
|
|
2
2
|
import * as factory from '../../../factory';
|
|
3
3
|
export type IDocTypeAsProduct = Omit<factory.product.IProduct, 'id'>;
|
|
4
4
|
export interface IDocTypeAsProductOffer {
|
|
5
|
-
offers?:
|
|
5
|
+
offers?: [];
|
|
6
6
|
}
|
|
7
7
|
type IDocType = IDocTypeAsProduct & IDocTypeAsProductOffer;
|
|
8
8
|
type IModel = Model<IDocType>;
|
|
@@ -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
|
*/
|
package/lib/chevre/repo/note.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
deleteNotesByIds(params
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
*/
|
|
@@ -48,7 +48,7 @@ class ProductRepo {
|
|
|
48
48
|
}
|
|
49
49
|
// tslint:disable-next-line:max-func-body-length
|
|
50
50
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
51
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
52
52
|
// MongoDB検索条件
|
|
53
53
|
const andConditions = [];
|
|
54
54
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
@@ -111,15 +111,16 @@ class ProductRepo {
|
|
|
111
111
|
productID: { $regex: new RegExp(productIDRegex) }
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
114
|
+
// discontinue product.offers
|
|
115
|
+
// const offersElemMatch = params.offers?.$elemMatch;
|
|
116
|
+
// if (offersElemMatch !== undefined && offersElemMatch !== null) {
|
|
117
|
+
// andConditions.push({
|
|
118
|
+
// offers: {
|
|
119
|
+
// $elemMatch: offersElemMatch
|
|
120
|
+
// }
|
|
121
|
+
// });
|
|
122
|
+
// }
|
|
123
|
+
const serviceOutputTypeOfEq = (_o = (_m = params.serviceOutput) === null || _m === void 0 ? void 0 : _m.typeOf) === null || _o === void 0 ? void 0 : _o.$eq;
|
|
123
124
|
if (typeof serviceOutputTypeOfEq === 'string') {
|
|
124
125
|
andConditions.push({
|
|
125
126
|
'serviceOutput.typeOf': {
|
|
@@ -128,7 +129,7 @@ class ProductRepo {
|
|
|
128
129
|
}
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
|
-
const serviceOutputAmountCurrencyEq = (
|
|
132
|
+
const serviceOutputAmountCurrencyEq = (_r = (_q = (_p = params.serviceOutput) === null || _p === void 0 ? void 0 : _p.amount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
|
|
132
133
|
if (typeof serviceOutputAmountCurrencyEq === 'string') {
|
|
133
134
|
andConditions.push({
|
|
134
135
|
'serviceOutput.amount.currency': {
|
|
@@ -137,7 +138,7 @@ class ProductRepo {
|
|
|
137
138
|
}
|
|
138
139
|
});
|
|
139
140
|
}
|
|
140
|
-
const serviceTypeCodeValueEq = (
|
|
141
|
+
const serviceTypeCodeValueEq = (_t = (_s = params.serviceType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
|
|
141
142
|
if (typeof serviceTypeCodeValueEq === 'string') {
|
|
142
143
|
andConditions.push({
|
|
143
144
|
'serviceType.codeValue': {
|
|
@@ -146,7 +147,7 @@ class ProductRepo {
|
|
|
146
147
|
}
|
|
147
148
|
});
|
|
148
149
|
}
|
|
149
|
-
const nameRegex = (
|
|
150
|
+
const nameRegex = (_u = params.name) === null || _u === void 0 ? void 0 : _u.$regex;
|
|
150
151
|
if (typeof nameRegex === 'string' && nameRegex.length > 0) {
|
|
151
152
|
const nameRegexExp = new RegExp(nameRegex);
|
|
152
153
|
andConditions.push({
|
|
@@ -156,7 +157,7 @@ class ProductRepo {
|
|
|
156
157
|
]
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
|
-
const additionalPropertyElemMatchNameEq = (
|
|
160
|
+
const additionalPropertyElemMatchNameEq = (_v = params.additionalPropertyMatch) === null || _v === void 0 ? void 0 : _v.nameEq;
|
|
160
161
|
if (typeof additionalPropertyElemMatchNameEq === 'string') {
|
|
161
162
|
andConditions.push({
|
|
162
163
|
additionalProperty: {
|
|
@@ -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.
|
|
15
|
-
"@cinerino/sdk": "12.5.0-alpha.
|
|
14
|
+
"@chevre/factory": "5.1.0-alpha.1",
|
|
15
|
+
"@cinerino/sdk": "12.5.0-alpha.7",
|
|
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.
|
|
118
|
+
"version": "23.0.0-alpha.6"
|
|
119
119
|
}
|