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

feat: internal to MongoDB $jsonSchema conversion COMPASS-8701 #218

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
".esm-wrapper.mjs"
],
"scripts": {
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/*.ts",
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/*.ts src/**/*.test.ts",
"test-example-parse-from-file": "ts-node examples/parse-from-file.ts",
"test-example-parse-schema": "ts-node examples/parse-schema.ts",
"test-time": "ts-node ./test/time-testing.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
SimplifiedSchema
} from './schema-analyzer';
import * as schemaStats from './stats';
import { AnyIterable, StandardJSONSchema, MongoDBJSONSchema, ExtendedJSONSchema } from './types';
import { AnyIterable, StandardJSONSchema, MongoDBJSONSchema, ExpandedJSONSchema } from './types';

/**
* Analyze documents - schema can be retrieved in different formats.
Expand Down Expand Up @@ -77,7 +77,7 @@ export type {
SimplifiedSchema,
StandardJSONSchema,
MongoDBJSONSchema,
ExtendedJSONSchema
ExpandedJSONSchema
};

export {
Expand Down
14 changes: 7 additions & 7 deletions src/schema-accessor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Schema as InternalSchema } from './schema-analyzer';
import convertors from './schema-convertors';
import { ExtendedJSONSchema, MongoDBJSONSchema, StandardJSONSchema } from './types';
import { convertors } from './schema-convertors';
import { ExpandedJSONSchema, MongoDBJSONSchema, StandardJSONSchema } from './types';

export interface SchemaAccessor {
getStandardJsonSchema: () => Promise<StandardJSONSchema>;
getMongoDBJsonSchema: () => Promise<MongoDBJSONSchema>;
getExtendedJsonSchema: () => Promise<ExtendedJSONSchema>;
getExpandedJSONSchema: () => Promise<ExpandedJSONSchema>;
getInternalSchema: () => Promise<InternalSchema>;
}

Expand All @@ -23,13 +23,13 @@ export class InternalSchemaBasedAccessor implements SchemaAccessor {
private internalSchema: InternalSchema;
private standardJSONSchema?: StandardJSONSchema;
private mongodbJSONSchema?: MongoDBJSONSchema;
private extendedJSONSchema?: ExtendedJSONSchema;
private ExpandedJSONSchema?: ExpandedJSONSchema;

constructor(internalSchema: InternalSchema) {
this.internalSchema = internalSchema;
}

async getInternalSchema(options?: Options): Promise<InternalSchema> {
async getInternalSchema(): Promise<InternalSchema> {
return this.internalSchema;
}

Expand All @@ -41,7 +41,7 @@ export class InternalSchemaBasedAccessor implements SchemaAccessor {
return this.mongodbJSONSchema ??= await convertors.internalSchemaToMongoDB(this.internalSchema, options);
}

async getExtendedJsonSchema(options: Options = {}): Promise<ExtendedJSONSchema> {
return this.extendedJSONSchema ??= await convertors.internalSchemaToExtended(this.internalSchema, options);
async getExpandedJSONSchema(options: Options = {}): Promise<ExpandedJSONSchema> {
return this.ExpandedJSONSchema ??= await convertors.internalSchemaToExpanded(this.internalSchema, options);
}
}
35 changes: 0 additions & 35 deletions src/schema-convertors.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/schema-convertors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import internalSchemaToExpanded from './internalToExpanded';
import internalSchemaToMongoDB from './internalToMongoDB';
import internalSchemaToStandard from './internalToStandard';

export const convertors = {
internalSchemaToStandard,
internalSchemaToMongoDB,
internalSchemaToExpanded
};
12 changes: 12 additions & 0 deletions src/schema-convertors/internalToExpanded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { InternalSchema } from '..';
import { ExpandedJSONSchema } from '../types';

export default function internalSchemaToExpanded(
/* eslint @typescript-eslint/no-unused-vars: 0 */
internalSchema: InternalSchema,
options: {
signal?: AbortSignal
}): Promise<ExpandedJSONSchema> {
// TODO: COMPASS-8702
return Promise.resolve({} as ExpandedJSONSchema);
}
Loading
Loading