Skip to content

Commit 530563f

Browse files
feat: internal to MongoDB $jsonSchema conversion COMPASS-8701 (#218)
--------- Co-authored-by: Anna Henningsen <[email protected]>
1 parent 591fa39 commit 530563f

12 files changed

+1930
-52
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
".esm-wrapper.mjs"
3434
],
3535
"scripts": {
36-
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/*.ts",
36+
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/*.ts src/**/*.test.ts",
3737
"test-example-parse-from-file": "ts-node examples/parse-from-file.ts",
3838
"test-example-parse-schema": "ts-node examples/parse-schema.ts",
3939
"test-time": "ts-node ./test/time-testing.ts",

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
SimplifiedSchema
1919
} from './schema-analyzer';
2020
import * as schemaStats from './stats';
21-
import { AnyIterable, StandardJSONSchema, MongoDBJSONSchema, ExtendedJSONSchema } from './types';
21+
import { AnyIterable, StandardJSONSchema, MongoDBJSONSchema, ExpandedJSONSchema } from './types';
2222

2323
/**
2424
* Analyze documents - schema can be retrieved in different formats.
@@ -77,7 +77,7 @@ export type {
7777
SimplifiedSchema,
7878
StandardJSONSchema,
7979
MongoDBJSONSchema,
80-
ExtendedJSONSchema
80+
ExpandedJSONSchema
8181
};
8282

8383
export {

src/schema-accessor.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Schema as InternalSchema } from './schema-analyzer';
2-
import convertors from './schema-convertors';
3-
import { ExtendedJSONSchema, MongoDBJSONSchema, StandardJSONSchema } from './types';
2+
import { convertors } from './schema-convertors';
3+
import { ExpandedJSONSchema, MongoDBJSONSchema, StandardJSONSchema } from './types';
44

55
export interface SchemaAccessor {
66
getStandardJsonSchema: () => Promise<StandardJSONSchema>;
77
getMongoDBJsonSchema: () => Promise<MongoDBJSONSchema>;
8-
getExtendedJsonSchema: () => Promise<ExtendedJSONSchema>;
8+
getExpandedJSONSchema: () => Promise<ExpandedJSONSchema>;
99
getInternalSchema: () => Promise<InternalSchema>;
1010
}
1111

@@ -23,13 +23,13 @@ export class InternalSchemaBasedAccessor implements SchemaAccessor {
2323
private internalSchema: InternalSchema;
2424
private standardJSONSchema?: StandardJSONSchema;
2525
private mongodbJSONSchema?: MongoDBJSONSchema;
26-
private extendedJSONSchema?: ExtendedJSONSchema;
26+
private ExpandedJSONSchema?: ExpandedJSONSchema;
2727

2828
constructor(internalSchema: InternalSchema) {
2929
this.internalSchema = internalSchema;
3030
}
3131

32-
async getInternalSchema(options?: Options): Promise<InternalSchema> {
32+
async getInternalSchema(): Promise<InternalSchema> {
3333
return this.internalSchema;
3434
}
3535

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

44-
async getExtendedJsonSchema(options: Options = {}): Promise<ExtendedJSONSchema> {
45-
return this.extendedJSONSchema ??= await convertors.internalSchemaToExtended(this.internalSchema, options);
44+
async getExpandedJSONSchema(options: Options = {}): Promise<ExpandedJSONSchema> {
45+
return this.ExpandedJSONSchema ??= await convertors.internalSchemaToExpanded(this.internalSchema, options);
4646
}
4747
}

src/schema-convertors.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/schema-convertors/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import internalSchemaToExpanded from './internalToExpanded';
2+
import internalSchemaToMongoDB from './internalToMongoDB';
3+
import internalSchemaToStandard from './internalToStandard';
4+
5+
export const convertors = {
6+
internalSchemaToStandard,
7+
internalSchemaToMongoDB,
8+
internalSchemaToExpanded
9+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { InternalSchema } from '..';
2+
import { ExpandedJSONSchema } from '../types';
3+
4+
export default function internalSchemaToExpanded(
5+
/* eslint @typescript-eslint/no-unused-vars: 0 */
6+
internalSchema: InternalSchema,
7+
options: {
8+
signal?: AbortSignal
9+
}): Promise<ExpandedJSONSchema> {
10+
// TODO: COMPASS-8702
11+
return Promise.resolve({} as ExpandedJSONSchema);
12+
}

0 commit comments

Comments
 (0)