Skip to content

Commit

Permalink
Merge pull request #266 from HPInc/feat/add-support-for-nested-types
Browse files Browse the repository at this point in the history
feat(mongoose): add support for nested properties with name "type"
  • Loading branch information
Adrià authored Feb 15, 2024
2 parents 9cfa496 + 967d66d commit 71b6a1d
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 141 deletions.
208 changes: 104 additions & 104 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
version: 2.1

jobs:
checkout_and_test:
parameters:
mongo-version:
type: string
docker-image:
type: string
docker:
- image: << parameters.docker-image >>
- image: circleci/mongo:<< parameters.mongo-version >>
- image: rabbitmq:3.9-alpine
steps:
- checkout
# - restore_cache:
# keys:
# - v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
# - v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}
# - v2-npm-deps-{{ .Branch }}
# - v2-npm-deps-
- run:
name: install NPM dependencies
command: |
echo -e "//registry.npmjs.org/:_authToken=$NPM_TOKEN\nscope=@davinci" > .npmrc
npm install
# - save_cache:
# key: v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
# paths:
# - node_modules
- run:
name: build
command: |
npm run build
- run:
name: test
command: |
npm run cover
- when:
condition:
and:
- equal: [ "5", << parameters.mongo-version >> ]
- equal: [ "cimg/node:18.16.0", << parameters.docker-image >> ]
steps:
checkout_and_test:
parameters:
mongo-version:
type: string
docker-image:
type: string
docker:
- image: << parameters.docker-image >>
- image: mongo:<< parameters.mongo-version >>
- image: rabbitmq:3.9-alpine
steps:
- checkout
# - restore_cache:
# keys:
# - v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
# - v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}
# - v2-npm-deps-{{ .Branch }}
# - v2-npm-deps-
- run:
name: upload coverage report
command: |
npx codecov -f packages/core/coverage/lcov.info -F core
npx codecov -f packages/http-server/coverage/lcov.info -F http-server
npx codecov -f packages/http-server-express/coverage/lcov.info -F http-server-express
npx codecov -f packages/reflector/coverage/lcov.info -F reflector
- save_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
paths:
- "~"
publish:
docker:
- image: cimg/node:16.18.1
steps:
- restore_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
- add_ssh_keys
- run:
name: Add github to known_hosts
command: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
- run:
name: publish
command: |
git config --global user.email "[email protected]"
git config --global user.name "CircleCI"
git checkout -f
npm run semantic-release
name: install NPM dependencies
command: |
echo -e "//registry.npmjs.org/:_authToken=$NPM_TOKEN\nscope=@davinci" > .npmrc
npm install
# - save_cache:
# key: v2-npm-deps-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
# paths:
# - node_modules
- run:
name: build
command: |
npm run build
- run:
name: test
command: |
npm run cover
- when:
condition:
and:
- equal: ['6', << parameters.mongo-version >>]
- equal: ['cimg/node:20.11', << parameters.docker-image >>]
steps:
- run:
name: upload coverage report
command: |
npx codecov -f packages/core/coverage/lcov.info -F core
npx codecov -f packages/http-server/coverage/lcov.info -F http-server
npx codecov -f packages/http-server-express/coverage/lcov.info -F http-server-express
npx codecov -f packages/reflector/coverage/lcov.info -F reflector
- save_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
paths:
- '~'
publish:
docker:
- image: cimg/node:20.11
steps:
- restore_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
- add_ssh_keys
- run:
name: Add github to known_hosts
command: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
- run:
name: publish
command: |
git config --global user.email "[email protected]"
git config --global user.name "CircleCI"
git checkout -f
npm run semantic-release
publish_docs:
docker:
- image: cimg/node:16.18.1
steps:
- restore_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
- add_ssh_keys
- run:
name: Deploy docs
command: |
rm .npmrc
sh ./docs/deploy.sh
publish_docs:
docker:
- image: cimg/node:20.11
steps:
- restore_cache:
key: v1-source-{{ .Environment.CIRCLE_SHA1 }}
- add_ssh_keys
- run:
name: Deploy docs
command: |
rm .npmrc
sh ./docs/deploy.sh
workflows:
version: 2
build_and_publish:
jobs:
- checkout_and_test:
matrix:
parameters:
mongo-version: ["4.4", "5"]
docker-image: ["circleci/node:14", "circleci/node:16", "cimg/node:18.16.0"]
- publish:
requires:
- checkout_and_test
filters:
branches:
only:
- master
- publish_docs:
requires:
- checkout_and_test
filters:
branches:
only:
- master
version: 2
build_and_publish:
jobs:
- checkout_and_test:
matrix:
parameters:
mongo-version: ['5', '6']
docker-image: ['cimg/node:18.19', 'cimg/node:20.11', 'cimg/node:lts']
- publish:
requires:
- checkout_and_test
filters:
branches:
only:
- master
- publish_docs:
requires:
- checkout_and_test
filters:
branches:
only:
- master
6 changes: 3 additions & 3 deletions packages/mongoose/src/generateModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ export const generateSchema = <T>(

const prop = {
...omit(options ?? {}, ['type']),
type
$type: type
};

return {
...acc,
[reflection.name]: isArray ? [prop.type] : prop
[reflection.name]: isArray ? { ...prop, $type: [prop.$type], default: prop.default || undefined } : prop
};
}, {});

Expand All @@ -128,7 +128,7 @@ export const generateSchema = <T>(
const schemaOptions = schemaDecoration?.options;
const schema: Schema<U> =
(forceCreateSchema || schemaDecoration) &&
new Schema(definition, { ...(mergedOptions ?? schemaOptions) });
new Schema(definition, { ...(mergedOptions ?? schemaOptions), typeKey: '$type' });

// register methods
const methods = classReflection.methods.reduce((acc, methodReflection) => {
Expand Down
Loading

0 comments on commit 71b6a1d

Please sign in to comment.