@chevre/domain 22.14.0-alpha.0 → 22.14.0-alpha.2

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,58 @@
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
+
14
+ const creatingNote: Pick<
15
+ chevre.factory.creativeWork.noteDigitalDocument.INoteAboutProduct,
16
+ 'about' | 'creator' | 'identifier' | 'project' | 'provider' | 'text' | 'version' | 'hasDigitalDocumentPermission'
17
+ > = {
18
+ about: { id: '656038908b1cd5ce629f5992', typeOf: chevre.factory.product.ProductType.EventService },
19
+ creator: { id: 'xxx', typeOf: chevre.factory.personType.Person },
20
+ identifier: 'abcdefgh',
21
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
22
+ provider: { id: project.id, typeOf: chevre.factory.organizationType.Project },
23
+ text: 'sample note text...',
24
+ version: '1',
25
+ hasDigitalDocumentPermission: []
26
+
27
+ };
28
+ const createResult = await noteRepo.upsertNotesByIdentifier(
29
+ [
30
+ {
31
+ $set: creatingNote
32
+ // $unset: {}
33
+ },
34
+ {
35
+ $set: creatingNote
36
+ // $unset: {}
37
+ }
38
+ ],
39
+ { update: false }
40
+ );
41
+ // tslint:disable-next-line:no-null-keyword
42
+ console.dir(createResult, { depth: null });
43
+
44
+ const updateResult = await noteRepo.upsertNotesByIdentifier(
45
+ [
46
+ {
47
+ $set: creatingNote
48
+ }
49
+ ],
50
+ { update: true }
51
+ );
52
+ // tslint:disable-next-line:no-null-keyword
53
+ console.dir(updateResult, { depth: null });
54
+ }
55
+
56
+ main()
57
+ .then()
58
+ .catch(console.error);
@@ -9,11 +9,8 @@ async function main() {
9
9
  const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
10
 
11
11
  const permissions = [
12
- 'assetTransactions.cancelReservation.write',
13
- 'orders.read',
14
- 'orders.update',
15
- 'reservations.attended',
16
- 'reservations.read'
12
+ 'notes.*',
13
+ 'notes.read'
17
14
  ];
18
15
  for (const permission of permissions) {
19
16
  const roles = await roleRepo.projectFields(
@@ -1,10 +1,13 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import * as factory from '../../../factory';
3
- type IDocType = factory.creativeWork.noteDigitalDocument.INoteDigitalDocument;
3
+ type IDocType = Pick<factory.creativeWork.noteDigitalDocument.INoteDigitalDocument, 'creator' | 'dateCreated' | 'dateModified' | 'editor' | 'hasDigitalDocumentPermission' | 'identifier' | 'project' | 'text' | 'typeOf' | 'version'> & {
4
+ about: factory.creativeWork.noteDigitalDocument.IAbout;
5
+ provider: factory.creativeWork.noteDigitalDocument.IProviderAsProject | factory.creativeWork.noteDigitalDocument.IProviderAsSeller;
6
+ };
4
7
  type IModel = Model<IDocType>;
5
8
  type ISchemaDefinition = SchemaDefinition<IDocType>;
6
9
  type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
7
10
  declare const modelName = "Note";
8
11
  declare const indexes: [d: IndexDefinition, o: IndexOptions][];
9
12
  declare function createSchema(): ISchema;
10
- export { createSchema, IModel, indexes, modelName };
13
+ export { createSchema, IDocType, IModel, indexes, modelName };
@@ -18,7 +18,8 @@ const schemaDefinition = {
18
18
  creator: { type: mongoose_1.SchemaTypes.Mixed, required: true },
19
19
  editor: mongoose_1.SchemaTypes.Mixed,
20
20
  version: { type: String, required: true },
21
- typeOf: { type: String, required: true }
21
+ typeOf: { type: String, required: true },
22
+ hasDigitalDocumentPermission: { type: mongoose_1.SchemaTypes.Mixed, required: false } // 2025-09-17~
22
23
  };
23
24
  const schemaOptions = {
24
25
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -1,3 +1,4 @@
1
+ import type { BulkWriteResult } from 'mongodb';
1
2
  import type { Connection, FilterQuery } from 'mongoose';
2
3
  import * as factory from '../factory';
3
4
  type INoteDigitalDocument = factory.creativeWork.noteDigitalDocument.INoteDigitalDocument;
@@ -12,6 +13,25 @@ export declare class NoteRepo {
12
13
  findNotes(params: factory.creativeWork.noteDigitalDocument.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<(INoteDigitalDocument & {
13
14
  id: string;
14
15
  })[]>;
16
+ /**
17
+ * メモ識別子をキーにして冪等置換
18
+ */
19
+ upsertNotesByIdentifier(params: {
20
+ $set: Pick<INoteDigitalDocument, 'about' | 'creator' | 'identifier' | 'project' | 'provider' | 'text' | 'version' | 'hasDigitalDocumentPermission'> & {
21
+ id?: never;
22
+ };
23
+ }[], options: {
24
+ /**
25
+ * falseの場合setOnInsertのみ
26
+ * trueの場合setのみ
27
+ */
28
+ update: boolean;
29
+ }): Promise<{
30
+ bulkWriteResult: BulkWriteResult;
31
+ modifiedNotes: {
32
+ id: string;
33
+ }[];
34
+ } | void>;
15
35
  deleteManyByAbout(params: {
16
36
  about: {
17
37
  id: string;
@@ -24,7 +24,8 @@ const AVAILABLE_PROJECT_FIELDS = [
24
24
  'creator',
25
25
  'editor',
26
26
  'version',
27
- 'typeOf'
27
+ 'typeOf',
28
+ 'hasDigitalDocumentPermission'
28
29
  ];
29
30
  /**
30
31
  * メモリポジトリ
@@ -34,7 +35,7 @@ class NoteRepo {
34
35
  this.noteModel = connection.model(note_1.modelName, (0, note_1.createSchema)());
35
36
  }
36
37
  static CREATE_MONGO_CONDITIONS(params) {
37
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
38
39
  const andConditions = [];
39
40
  const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
40
41
  if (Array.isArray(idIn)) {
@@ -64,11 +65,15 @@ class NoteRepo {
64
65
  if (Array.isArray(aboutOrderNumberIn)) {
65
66
  andConditions.push({ 'about.orderNumber': { $exists: true, $in: aboutOrderNumberIn } });
66
67
  }
67
- const identifierEq = (_p = params.identifier) === null || _p === void 0 ? void 0 : _p.$eq;
68
+ const aboutTypeOfEq = (_q = (_p = params.about) === null || _p === void 0 ? void 0 : _p.typeOf) === null || _q === void 0 ? void 0 : _q.$eq;
69
+ if (typeof aboutTypeOfEq === 'string') {
70
+ andConditions.push({ 'about.typeOf': { $eq: aboutTypeOfEq } });
71
+ }
72
+ const identifierEq = (_r = params.identifier) === null || _r === void 0 ? void 0 : _r.$eq;
68
73
  if (typeof identifierEq === 'string') {
69
74
  andConditions.push({ identifier: { $eq: identifierEq } });
70
75
  }
71
- const identifierIn = (_q = params.identifier) === null || _q === void 0 ? void 0 : _q.$in;
76
+ const identifierIn = (_s = params.identifier) === null || _s === void 0 ? void 0 : _s.$in;
72
77
  if (Array.isArray(identifierIn)) {
73
78
  andConditions.push({ identifier: { $in: identifierIn } });
74
79
  }
@@ -96,10 +101,84 @@ class NoteRepo {
96
101
  .skip(params.limit * (page - 1));
97
102
  }
98
103
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
99
- .lean() // 2024-09-19~
104
+ .lean()
100
105
  .exec();
101
106
  });
102
107
  }
108
+ /**
109
+ * メモ識別子をキーにして冪等置換
110
+ */
111
+ upsertNotesByIdentifier(params, options) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const now = new Date();
114
+ const { update } = options;
115
+ const bulkWriteOps = [];
116
+ const queryFilters = [];
117
+ if (Array.isArray(params)) {
118
+ params.forEach(({ $set }) => {
119
+ const { about, creator, identifier, project, provider, text, version, hasDigitalDocumentPermission } = $set;
120
+ if (typeof identifier !== 'string' || identifier.length === 0) {
121
+ throw new factory.errors.ArgumentNull('identifier');
122
+ }
123
+ if (typeof version !== 'string' || version.length === 0) {
124
+ throw new factory.errors.ArgumentNull('version');
125
+ }
126
+ if (typeof text !== 'string') {
127
+ throw new factory.errors.ArgumentNull('text');
128
+ }
129
+ // リソースのユニークネスを保証するfilter
130
+ const filter = {
131
+ 'project.id': { $eq: project.id },
132
+ 'about.id': { $eq: about.id },
133
+ identifier: { $eq: identifier },
134
+ version: { $eq: version }
135
+ };
136
+ queryFilters.push({
137
+ 'project.id': { $eq: project.id },
138
+ 'about.id': { $eq: about.id },
139
+ identifier: { $eq: identifier },
140
+ version: { $eq: version }
141
+ });
142
+ if (update === true) {
143
+ const setFields = Object.assign({ dateModified: now, editor: creator, text }, (Array.isArray(hasDigitalDocumentPermission)) ? { hasDigitalDocumentPermission } : undefined);
144
+ const updateFilter = {
145
+ $set: setFields
146
+ // ...($unset !== undefined) ? { $unset } : undefined
147
+ };
148
+ const updateOne = {
149
+ filter,
150
+ update: updateFilter,
151
+ upsert: false
152
+ };
153
+ bulkWriteOps.push({ updateOne });
154
+ }
155
+ else {
156
+ const setOnInsert = Object.assign({ about, creator, identifier, project, provider, version, dateCreated: now, typeOf: factory.creativeWorkType.NoteDigitalDocument, text }, (Array.isArray(hasDigitalDocumentPermission)) ? { hasDigitalDocumentPermission } : undefined);
157
+ const updateFilter = {
158
+ $setOnInsert: setOnInsert
159
+ };
160
+ const updateOne = {
161
+ filter,
162
+ update: updateFilter,
163
+ upsert: true
164
+ };
165
+ bulkWriteOps.push({ updateOne });
166
+ }
167
+ });
168
+ }
169
+ if (bulkWriteOps.length > 0) {
170
+ const bulkWriteResult = yield this.noteModel.bulkWrite(bulkWriteOps, { ordered: false });
171
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
172
+ const modifiedNotes = yield this.noteModel.find({ $or: queryFilters }, {
173
+ _id: 0,
174
+ id: { $toString: '$_id' }
175
+ })
176
+ .lean()
177
+ .exec();
178
+ return { bulkWriteResult, modifiedNotes };
179
+ }
180
+ });
181
+ }
103
182
  deleteManyByAbout(params) {
104
183
  return __awaiter(this, void 0, void 0, function* () {
105
184
  return this.noteModel.deleteMany({
package/package.json CHANGED
@@ -11,7 +11,7 @@
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": "4.399.0-alpha.0",
14
+ "@chevre/factory": "4.399.0-alpha.2",
15
15
  "@cinerino/sdk": "12.2.0",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.4.0-alpha.1",
@@ -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": "22.14.0-alpha.0"
118
+ "version": "22.14.0-alpha.2"
119
119
  }