Comparing version 15.2.0 to 15.2.1
import { Db } from 'mongodb'; | ||
import { Model } from './model'; | ||
import schema, { SchemaOptions } from './schema'; | ||
import { SchemaOptions } from './schema'; | ||
import types from './types'; | ||
@@ -84,3 +84,3 @@ import { BaseSchema, ModelOptions } from './utils'; | ||
} | ||
export { schema, types, types as Types }; | ||
export { types, types as Types }; | ||
export * from './hooks'; | ||
@@ -87,0 +87,0 @@ export * from './model'; |
@@ -20,6 +20,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Types = exports.types = exports.schema = void 0; | ||
exports.Types = exports.types = void 0; | ||
const model_1 = require("./model"); | ||
const schema_1 = __importDefault(require("./schema")); | ||
exports.schema = schema_1.default; | ||
const types_1 = __importDefault(require("./types")); | ||
@@ -26,0 +24,0 @@ exports.types = types_1.default; |
@@ -36,2 +36,4 @@ import { WithId } from 'mongodb'; | ||
* | ||
* The `defaults` option can be a static object, a function that returns an object or an async function that returns an object. | ||
* | ||
* @name schema | ||
@@ -49,3 +51,3 @@ * | ||
* @example | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* import { schema, types } from 'papr'; | ||
* | ||
@@ -62,2 +64,7 @@ * const userSchema = schema({ | ||
* | ||
* @example | ||
* // Example with static defaults, timestamps and validation options | ||
* | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* | ||
* const orderSchema = schema({ | ||
@@ -76,4 +83,46 @@ * _id: types.number({ required: true }), | ||
* export type OrderOptions = typeof orderSchema[1]; | ||
* | ||
* @example | ||
* // Example with dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: () => ({ | ||
* birthDate: new Date(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
* | ||
* @example | ||
* // Example with async dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* function getDateAsync(): Promise<Date> { | ||
* return Promise.resolve(new Date()); | ||
* } | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: async () => ({ | ||
* birthDate: await getDateAsync(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
*/ | ||
export default function schema<TProperties extends Record<string, unknown>, TOptions extends SchemaOptions<TProperties>>(properties: TProperties, options?: TOptions): [SchemaType<TProperties, TOptions>, TOptions]; | ||
export declare function schema<TProperties extends Record<string, unknown>, TOptions extends SchemaOptions<TProperties>>(properties: TProperties, options?: TOptions): [SchemaType<TProperties, TOptions>, TOptions]; | ||
export {}; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.schema = void 0; | ||
const types_1 = __importDefault(require("./types")); | ||
@@ -44,2 +45,4 @@ const utils_1 = require("./utils"); | ||
* | ||
* The `defaults` option can be a static object, a function that returns an object or an async function that returns an object. | ||
* | ||
* @name schema | ||
@@ -57,3 +60,3 @@ * | ||
* @example | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* import { schema, types } from 'papr'; | ||
* | ||
@@ -70,2 +73,7 @@ * const userSchema = schema({ | ||
* | ||
* @example | ||
* // Example with static defaults, timestamps and validation options | ||
* | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* | ||
* const orderSchema = schema({ | ||
@@ -84,2 +92,44 @@ * _id: types.number({ required: true }), | ||
* export type OrderOptions = typeof orderSchema[1]; | ||
* | ||
* @example | ||
* // Example with dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: () => ({ | ||
* birthDate: new Date(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
* | ||
* @example | ||
* // Example with async dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* function getDateAsync(): Promise<Date> { | ||
* return Promise.resolve(new Date()); | ||
* } | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: async () => ({ | ||
* birthDate: await getDateAsync(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
*/ | ||
@@ -113,2 +163,2 @@ function schema(properties, options) { | ||
} | ||
exports.default = schema; | ||
exports.schema = schema; |
import { Db } from 'mongodb'; | ||
import { Model } from './model.js'; | ||
import schema, { SchemaOptions } from './schema.js'; | ||
import { SchemaOptions } from './schema.js'; | ||
import types from './types.js'; | ||
@@ -84,3 +84,3 @@ import { BaseSchema, ModelOptions } from './utils.js'; | ||
} | ||
export { schema, types, types as Types }; | ||
export { types, types as Types }; | ||
export * from './hooks.js'; | ||
@@ -87,0 +87,0 @@ export * from './model.js'; |
import { abstract, build } from './model.js'; | ||
import schema from './schema.js'; | ||
import types from './types.js'; | ||
@@ -148,3 +147,3 @@ export default class Papr { | ||
} | ||
export { schema, types, types as Types }; | ||
export { types, types as Types }; | ||
export * from './hooks.js'; | ||
@@ -151,0 +150,0 @@ export * from './model.js'; |
@@ -36,2 +36,4 @@ import { WithId } from 'mongodb'; | ||
* | ||
* The `defaults` option can be a static object, a function that returns an object or an async function that returns an object. | ||
* | ||
* @name schema | ||
@@ -49,3 +51,3 @@ * | ||
* @example | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* import { schema, types } from 'papr'; | ||
* | ||
@@ -62,2 +64,7 @@ * const userSchema = schema({ | ||
* | ||
* @example | ||
* // Example with static defaults, timestamps and validation options | ||
* | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* | ||
* const orderSchema = schema({ | ||
@@ -76,4 +83,46 @@ * _id: types.number({ required: true }), | ||
* export type OrderOptions = typeof orderSchema[1]; | ||
* | ||
* @example | ||
* // Example with dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: () => ({ | ||
* birthDate: new Date(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
* | ||
* @example | ||
* // Example with async dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* function getDateAsync(): Promise<Date> { | ||
* return Promise.resolve(new Date()); | ||
* } | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: async () => ({ | ||
* birthDate: await getDateAsync(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
*/ | ||
export default function schema<TProperties extends Record<string, unknown>, TOptions extends SchemaOptions<TProperties>>(properties: TProperties, options?: TOptions): [SchemaType<TProperties, TOptions>, TOptions]; | ||
export declare function schema<TProperties extends Record<string, unknown>, TOptions extends SchemaOptions<TProperties>>(properties: TProperties, options?: TOptions): [SchemaType<TProperties, TOptions>, TOptions]; | ||
export {}; |
@@ -38,2 +38,4 @@ import types from './types.js'; | ||
* | ||
* The `defaults` option can be a static object, a function that returns an object or an async function that returns an object. | ||
* | ||
* @name schema | ||
@@ -51,3 +53,3 @@ * | ||
* @example | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* import { schema, types } from 'papr'; | ||
* | ||
@@ -64,2 +66,7 @@ * const userSchema = schema({ | ||
* | ||
* @example | ||
* // Example with static defaults, timestamps and validation options | ||
* | ||
* import { schema, types, VALIDATION_ACTIONS, VALIDATION_LEVEL } from 'papr'; | ||
* | ||
* const orderSchema = schema({ | ||
@@ -78,4 +85,46 @@ * _id: types.number({ required: true }), | ||
* export type OrderOptions = typeof orderSchema[1]; | ||
* | ||
* @example | ||
* // Example with dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: () => ({ | ||
* birthDate: new Date(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
* | ||
* @example | ||
* // Example with async dynamic defaults | ||
* | ||
* import { schema, types } from 'papr'; | ||
* | ||
* function getDateAsync(): Promise<Date> { | ||
* return Promise.resolve(new Date()); | ||
* } | ||
* | ||
* const userSchema = schema({ | ||
* active: types.boolean(), | ||
* birthDate: types.date(), | ||
* firstName: types.string({ required: true }), | ||
* lastName: types.string({ required: true }), | ||
* }, { | ||
* defaults: async () => ({ | ||
* birthDate: await getDateAsync(); | ||
* }) | ||
* }); | ||
* | ||
* export type UserDocument = (typeof userSchema)[0]; | ||
* export type UserOptions = (typeof userSchema)[1]; | ||
*/ | ||
export default function schema(properties, options) { | ||
export function schema(properties, options) { | ||
const { defaults, timestamps = false, validationAction = VALIDATION_ACTIONS.ERROR, validationLevel = VALIDATION_LEVEL.STRICT, } = options || {}; | ||
@@ -82,0 +131,0 @@ const createdAtProperty = getTimestampProperty('createdAt', timestamps); |
@@ -5,3 +5,3 @@ { | ||
"author": "Plex Inc.", | ||
"version": "15.2.0", | ||
"version": "15.2.1", | ||
"keywords": [ | ||
@@ -59,13 +59,13 @@ "mongodb", | ||
"devDependencies": { | ||
"@babel/core": "7.23.7", | ||
"@babel/preset-env": "7.23.7", | ||
"@babel/core": "7.24.0", | ||
"@babel/preset-env": "7.24.0", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@commitlint/cli": "18.6.0", | ||
"@commitlint/config-conventional": "18.6.0", | ||
"@commitlint/cli": "19.0.3", | ||
"@commitlint/config-conventional": "19.0.3", | ||
"@types/node": "20.11.7", | ||
"@typescript-eslint/eslint-plugin": "6.20.0", | ||
"@typescript-eslint/parser": "6.20.0", | ||
"@typescript-eslint/eslint-plugin": "7.1.0", | ||
"@typescript-eslint/parser": "7.1.0", | ||
"arg": "5.0.2", | ||
"docsify-cli": "4.4.4", | ||
"eslint": "8.56.0", | ||
"eslint": "8.57.0", | ||
"eslint-config-prettier": "9.1.0", | ||
@@ -77,16 +77,16 @@ "eslint-config-standard": "17.1.0", | ||
"eslint-plugin-promise": "6.1.1", | ||
"husky": "9.0.6", | ||
"husky": "9.0.11", | ||
"jest": "29.7.0", | ||
"jsdoc-api": "8.0.0", | ||
"jsdoc-parse": "6.2.0", | ||
"jsdoc-parse": "6.2.1", | ||
"lint-staged": "15.2.0", | ||
"mongodb": "6.3.0", | ||
"mongodb": "6.4.0", | ||
"mongodb-memory-server": "9.1.1", | ||
"mongoose": "7.5.2", | ||
"pinst": "3.0.0", | ||
"prettier": "3.2.2", | ||
"prettier": "3.2.5", | ||
"standard-version": "9.5.0", | ||
"ts-expect": "1.3.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.3.2" | ||
"typescript": "5.4.2" | ||
}, | ||
@@ -93,0 +93,0 @@ "peerDependencies": { |
236420
6134