Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create collections specific for ddo versions #225

Merged
merged 19 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions schemas/v4/op_ddo_v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "op_ddo_v4.1.0",
"enable_nested_fields": true,
"fields": [{ "name": ".*", "type": "auto", "optional": true }]
}
5 changes: 5 additions & 0 deletions schemas/v4/op_ddo_v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "op_ddo_v4.3.0",
"enable_nested_fields": true,
"fields": [{ "name": ".*", "type": "auto", "optional": true }]
}
5 changes: 5 additions & 0 deletions schemas/v4/op_ddo_v5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "op_ddo_v4.5.0",
"enable_nested_fields": true,
"fields": [{ "name": ".*", "type": "auto", "optional": true }]
}
10 changes: 5 additions & 5 deletions src/components/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ export class Database {
configureCustomDBTransport(this, DATABASE_LOGGER)
}

this.ddo = await new DdoDatabase(config, schemas.ddoSchemas)
this.nonce = await new NonceDatabase(config, schemas.nonceSchemas)
this.indexer = await new IndexerDatabase(config, schemas.indexerSchemas)
this.logs = await new LogDatabase(config, schemas.logSchemas)
this.order = await new OrderDatabase(config, schemas.orderSchema)
this.ddo = await new DdoDatabase(this.config, schemas.ddoSchemas)
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
this.nonce = await new NonceDatabase(this.config, schemas.nonceSchemas)
this.indexer = await new IndexerDatabase(this.config, schemas.indexerSchemas)
this.logs = await new LogDatabase(this.config, schemas.logSchemas)
this.order = await new OrderDatabase(this.config, schemas.orderSchema)
return this
})() as unknown as Database
}
Expand Down
42 changes: 35 additions & 7 deletions src/components/database/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
import { TypesenseCollectionCreateSchema } from '../../@types/index.js'
import fs from 'fs'
import path, { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { DATABASE_LOGGER } from '../../utils/logging/common.js'
import { LOG_LEVELS_STR } from '../../utils/logging/Logger.js'

export function readJsonSchemas(): any[] {
const jsonDocuments: any[] = []
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
const pathToSchemaDir: string = '../../../schemas/v4'
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
const currentModulePath = fileURLToPath(import.meta.url)

// Use dirname to get the directory name
const currentDirectory = dirname(currentModulePath)
const schemaFilePath = resolve(currentDirectory, pathToSchemaDir)
const jsonFiles = fs
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
.readdirSync(schemaFilePath)
.filter((file) => path.extname(file) === '.json')
jsonFiles.forEach((file) => {
try {
// eslint-disable-next-line security/detect-non-literal-fs-filename
const fileData = fs.readFileSync(path.join(schemaFilePath, file), 'utf-8')
const jsonFile = JSON.parse(fileData.toString())
jsonDocuments.push(jsonFile)
} catch (err) {
DATABASE_LOGGER.log(
LOG_LEVELS_STR.LEVEL_ERROR,
`Error loading DDO schema from ${path.join(pathToSchemaDir, file)}: ${err}`,
true
)
}
})
return jsonDocuments
}

export type Schema = TypesenseCollectionCreateSchema
export type Schemas = {
Expand All @@ -8,14 +41,9 @@ export type Schemas = {
logSchemas: Schema
orderSchema: Schema
}
const ddoSchemas = readJsonSchemas()
export const schemas: Schemas = {
ddoSchemas: [
{
name: 'ddo_v0.1',
enable_nested_fields: true,
fields: [{ name: '.*', type: 'auto', optional: true }] // optional: true for turning the full version DDO into short one for states DEPRECATED and REVOKED
}
],
ddoSchemas,
nonceSchemas: {
name: 'nonce',
enable_nested_fields: true,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getConfig } from './utils/index.js'

import { GENERIC_EMOJIS, LOG_LEVELS_STR } from './utils/logging/Logger.js'
import fs from 'fs'
import path from 'path'
mariacarmina marked this conversation as resolved.
Show resolved Hide resolved
import { OCEAN_NODE_LOGGER } from './utils/logging/common.js'

const app: Express = express()
Expand Down Expand Up @@ -70,6 +71,7 @@ let dbconn = null
if (config.dbConfig?.url) {
// once we create a database instance, we check the environment and possibly add the DB transport
// after that, all loggers will eventually have it too (if in production/staging environments)
// it creates dinamically DDO schemas
dbconn = await new Database(config.dbConfig)
} else {
config.hasIndexer = false
Expand Down
Loading