@chevre/domain
Version:
Chevre Domain Library for Node.js
176 lines (175 loc) • 4.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.modelName = exports.indexes = void 0;
exports.createSchema = createSchema;
const mongoose_1 = require("mongoose");
const writeConcern_1 = require("../writeConcern");
const settings_1 = require("../../../settings");
const modelName = 'CreativeWork';
exports.modelName = modelName;
const schemaDefinition = {
project: mongoose_1.SchemaTypes.Mixed,
typeOf: {
type: String,
required: true
},
identifier: { type: String, required: true },
name: mongoose_1.SchemaTypes.Mixed,
// alternateName: String,
alternativeHeadline: String,
description: String,
// copyrightHolder: SchemaTypes.Mixed,
// copyrightYear: Number,
datePublished: Date,
distributor: mongoose_1.SchemaTypes.Mixed,
headline: String,
// license: String,
thumbnailUrl: String,
duration: String,
contentRating: String,
offers: mongoose_1.SchemaTypes.Mixed,
additionalProperty: mongoose_1.SchemaTypes.Mixed
};
const schemaOptions = {
autoIndex: settings_1.MONGO_AUTO_INDEX,
autoCreate: false,
collection: 'creativeWorks',
id: true,
read: settings_1.MONGO_READ_PREFERENCE,
writeConcern: writeConcern_1.writeConcern,
strict: true,
strictQuery: false,
timestamps: false, // 2024-09-09~
versionKey: false, // 2024-09-09~
toJSON: {
getters: false,
virtuals: false,
minimize: false,
versionKey: false
},
toObject: {
getters: false,
virtuals: true,
minimize: false,
versionKey: false
}
};
const indexes = [
[
{ identifier: 1 },
{
name: 'searchByIdentifier2'
}
],
[
{ 'project.id': 1, identifier: 1 },
{
name: 'searchByProjectId-v20220721'
}
],
[
{ name: 1, identifier: 1 },
{
name: 'searchByName2',
partialFilterExpression: {
name: { $exists: true }
}
}
],
[
{ 'name.ja': 1, identifier: 1 },
{
name: 'searchByNameJa',
partialFilterExpression: {
'name.ja': { $exists: true }
}
}
],
[
{ 'name.en': 1, identifier: 1 },
{
name: 'searchByNameEn',
partialFilterExpression: {
'name.en': { $exists: true }
}
}
],
[
{ datePublished: 1, identifier: 1 },
{
name: 'searchByDatePublished2',
partialFilterExpression: {
datePublished: { $exists: true }
}
}
],
[
{ 'offers.availabilityEnds': 1, identifier: 1 },
{
name: 'searchByOffersAvailabilityEnds2',
partialFilterExpression: {
'offers.availabilityEnds': { $exists: true }
}
}
],
[
{ 'offers.availabilityStarts': 1, identifier: 1 },
{
name: 'searchByOffersAvailabilityStarts2',
partialFilterExpression: {
'offers.availabilityStarts': { $exists: true }
}
}
],
[
{ contentRating: 1, identifier: 1 },
{
name: 'searchByContentRating',
partialFilterExpression: {
contentRating: { $exists: true }
}
}
],
[
{ 'distributor.codeValue': 1, identifier: 1 },
{
name: 'searchByDistributorCodeValue',
partialFilterExpression: {
'distributor.codeValue': { $exists: true }
}
}
],
[
{ additionalProperty: 1, identifier: 1 },
{
name: 'searchByAdditionalProperty',
partialFilterExpression: {
additionalProperty: { $exists: true }
}
}
],
[
// add unique index(2024-11-12~)
{ 'project.id': 1, identifier: 1 },
{
unique: true,
name: 'uniqueIdentifier'
}
]
];
exports.indexes = indexes;
/**
* コンテンツスキーマ
*/
let schema;
function createSchema() {
if (schema === undefined) {
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
if (settings_1.MONGO_AUTO_INDEX) {
indexes.forEach((indexParams) => {
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
});
}
}
return schema;
}