@chevre/domain 22.9.0 → 22.10.0-alpha.0
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,63 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { IIssuer } from '../../../../lib/chevre/repo/mongoose/schemas/issuer';
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// tslint:disable-next-line:max-func-body-length
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const issuerRepo = await chevre.repository.Issuer.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const cursor = issuerRepo.getCursor(
|
|
14
|
+
{
|
|
15
|
+
// 'project.id': { $ne: EXCLUDED_PROJECT_ID }
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
_id: 1,
|
|
19
|
+
project: 1,
|
|
20
|
+
identifier: 1,
|
|
21
|
+
url: 1,
|
|
22
|
+
name: 1
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
console.log('docs found');
|
|
26
|
+
|
|
27
|
+
let i = 0;
|
|
28
|
+
let updateCount = 0;
|
|
29
|
+
await cursor.eachAsync(async (doc) => {
|
|
30
|
+
i += 1;
|
|
31
|
+
const issuer: IIssuer = doc.toObject();
|
|
32
|
+
|
|
33
|
+
const alreadyMigrated = typeof issuer.url === 'string';
|
|
34
|
+
|
|
35
|
+
if (alreadyMigrated) {
|
|
36
|
+
console.log(
|
|
37
|
+
'already migrated.',
|
|
38
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
39
|
+
} else {
|
|
40
|
+
console.log(
|
|
41
|
+
'updating...',
|
|
42
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
43
|
+
await issuerRepo.saveIssuer({
|
|
44
|
+
id: issuer.id,
|
|
45
|
+
identifier: issuer.identifier,
|
|
46
|
+
name: { ja: issuer.identifier },
|
|
47
|
+
project: issuer.project,
|
|
48
|
+
url: issuer.identifier
|
|
49
|
+
});
|
|
50
|
+
updateCount += 1;
|
|
51
|
+
console.log(
|
|
52
|
+
'updated.',
|
|
53
|
+
issuer.id, issuer.project.id, issuer.identifier, i);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log(i, 'docs checked');
|
|
58
|
+
console.log(updateCount, 'docs updated');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
main()
|
|
62
|
+
.then()
|
|
63
|
+
.catch(console.error);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
|
-
import { IIssuer, ISearchConditions } from './mongoose/schemas/issuer';
|
|
2
|
+
import { IDocType, IIssuer, ISearchConditions } from './mongoose/schemas/issuer';
|
|
3
3
|
/**
|
|
4
4
|
* 発行者リポジトリ
|
|
5
5
|
*/
|
|
@@ -10,7 +10,7 @@ export declare class IssuerRepo {
|
|
|
10
10
|
saveIssuer(params: IIssuer): Promise<{
|
|
11
11
|
id: string;
|
|
12
12
|
}>;
|
|
13
|
-
projectPublicFields(params: ISearchConditions): Promise<Pick<IIssuer, 'id' | 'identifier' | 'project'>[]>;
|
|
13
|
+
projectPublicFields(params: ISearchConditions): Promise<Pick<IIssuer, 'id' | 'identifier' | 'project' | 'name' | 'url'>[]>;
|
|
14
14
|
findById(params: {
|
|
15
15
|
id: string;
|
|
16
16
|
project: {
|
|
@@ -22,11 +22,20 @@ export declare class IssuerRepo {
|
|
|
22
22
|
project: {
|
|
23
23
|
id: string;
|
|
24
24
|
};
|
|
25
|
-
}): Promise<IIssuer
|
|
25
|
+
}): Promise<Pick<IIssuer, 'id' | 'identifier' | 'project' | 'tokenSecret' | 'url'>>;
|
|
26
26
|
deleteById(params: {
|
|
27
27
|
id: string;
|
|
28
28
|
project: {
|
|
29
29
|
id: string;
|
|
30
30
|
};
|
|
31
31
|
}): Promise<void>;
|
|
32
|
+
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, IDocType> & IIssuer & {
|
|
33
|
+
hasMemberProgram?: import("./mongoose/schemas/issuer").IMemberProgram[];
|
|
34
|
+
} & {
|
|
35
|
+
_id: import("mongoose").Types.ObjectId;
|
|
36
|
+
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, IDocType> & IIssuer & {
|
|
37
|
+
hasMemberProgram?: import("./mongoose/schemas/issuer").IMemberProgram[];
|
|
38
|
+
} & {
|
|
39
|
+
_id: import("mongoose").Types.ObjectId;
|
|
40
|
+
}>>;
|
|
32
41
|
}
|
|
@@ -77,7 +77,9 @@ class IssuerRepo {
|
|
|
77
77
|
_id: 0,
|
|
78
78
|
id: { $toString: '$_id' },
|
|
79
79
|
identifier: 1,
|
|
80
|
-
project: 1
|
|
80
|
+
project: 1,
|
|
81
|
+
name: 1,
|
|
82
|
+
url: 1
|
|
81
83
|
};
|
|
82
84
|
const query = this.issuerModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
83
85
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
@@ -100,7 +102,9 @@ class IssuerRepo {
|
|
|
100
102
|
id: { $toString: '$_id' },
|
|
101
103
|
identifier: 1,
|
|
102
104
|
project: 1,
|
|
103
|
-
tokenSecret: 1
|
|
105
|
+
tokenSecret: 1,
|
|
106
|
+
name: 1,
|
|
107
|
+
url: 1
|
|
104
108
|
};
|
|
105
109
|
const query = this.issuerModel.findOne({
|
|
106
110
|
_id: { $eq: params.id },
|
|
@@ -122,7 +126,8 @@ class IssuerRepo {
|
|
|
122
126
|
id: { $toString: '$_id' },
|
|
123
127
|
identifier: 1,
|
|
124
128
|
project: 1,
|
|
125
|
-
tokenSecret: 1
|
|
129
|
+
tokenSecret: 1,
|
|
130
|
+
url: 1
|
|
126
131
|
};
|
|
127
132
|
const query = this.issuerModel.findOne({
|
|
128
133
|
identifier: { $eq: params.identifier },
|
|
@@ -146,5 +151,10 @@ class IssuerRepo {
|
|
|
146
151
|
.exec();
|
|
147
152
|
});
|
|
148
153
|
}
|
|
154
|
+
getCursor(conditions, projection) {
|
|
155
|
+
return this.issuerModel.find(conditions, projection)
|
|
156
|
+
.sort({ identifier: factory.sortType.Ascending })
|
|
157
|
+
.cursor();
|
|
158
|
+
}
|
|
149
159
|
}
|
|
150
160
|
exports.IssuerRepo = IssuerRepo;
|
|
@@ -20,9 +20,19 @@ export interface ISearchConditions {
|
|
|
20
20
|
}
|
|
21
21
|
export interface IIssuer {
|
|
22
22
|
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* 管理者定義の識別子
|
|
25
|
+
*/
|
|
23
26
|
identifier: string;
|
|
27
|
+
name: {
|
|
28
|
+
ja: string;
|
|
29
|
+
};
|
|
24
30
|
project: Pick<factory.project.IProject, 'id' | 'typeOf'>;
|
|
25
31
|
tokenSecret?: string;
|
|
32
|
+
/**
|
|
33
|
+
* トークンのiss
|
|
34
|
+
*/
|
|
35
|
+
url: string;
|
|
26
36
|
}
|
|
27
37
|
export interface IMemberProgram {
|
|
28
38
|
typeOf: 'MemberProgram';
|
|
@@ -11,7 +11,9 @@ const schemaDefinition = {
|
|
|
11
11
|
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
12
|
identifier: { type: String, required: true },
|
|
13
13
|
tokenSecret: String,
|
|
14
|
-
hasMemberProgram: [mongoose_1.SchemaTypes.Mixed]
|
|
14
|
+
hasMemberProgram: [mongoose_1.SchemaTypes.Mixed],
|
|
15
|
+
name: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
16
|
+
url: { type: String, required: true }
|
|
15
17
|
};
|
|
16
18
|
const schemaOptions = {
|
|
17
19
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -37,7 +39,37 @@ const schemaOptions = {
|
|
|
37
39
|
versionKey: false
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
|
-
const indexes = [
|
|
42
|
+
const indexes = [
|
|
43
|
+
[
|
|
44
|
+
{ identifier: 1 },
|
|
45
|
+
{ name: 'identifier' }
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
{ 'project.id': 1, identifier: 1 },
|
|
49
|
+
{
|
|
50
|
+
name: 'uniqueIdentifier',
|
|
51
|
+
unique: true
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
{ 'project.id': 1, 'hasMemberProgram.identifier': 1 },
|
|
56
|
+
{
|
|
57
|
+
name: 'uniqueMemberProgramIdentifier',
|
|
58
|
+
unique: true,
|
|
59
|
+
partialFilterExpression: {
|
|
60
|
+
'hasMemberProgram.identifier': { $exists: true }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
{ 'hasMemberProgram.identifier': 1, identifier: 1 },
|
|
66
|
+
{ name: 'hasMemberProgramIdentifier' }
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
{ url: 1, identifier: 1 },
|
|
70
|
+
{ name: 'url' }
|
|
71
|
+
]
|
|
72
|
+
];
|
|
41
73
|
exports.indexes = indexes;
|
|
42
74
|
/**
|
|
43
75
|
* 発行者スキーマ
|
package/package.json
CHANGED