ts-patch-mongoose 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +8 -8
- package/dist/index.cjs +395 -0
- package/dist/index.d.cts +75 -0
- package/dist/index.d.mts +75 -0
- package/dist/index.mjs +391 -0
- package/package.json +36 -29
- package/src/helpers.ts +1 -1
- package/src/hooks/delete-hooks.ts +4 -4
- package/src/hooks/update-hooks.ts +10 -10
- package/src/{plugin.ts → index.ts} +6 -2
- package/src/{models/History.ts → model.ts} +1 -1
- package/src/patch.ts +11 -11
- package/src/version.ts +2 -0
- package/tests/em.test.ts +1 -1
- package/tests/helpers.test.ts +2 -2
- package/tests/patch.test.ts +1 -1
- package/tests/plugin-event-created.test.ts +2 -2
- package/tests/plugin-event-deleted.test.ts +2 -2
- package/tests/plugin-event-updated.test.ts +2 -2
- package/tests/plugin-global.test.ts +2 -2
- package/tests/plugin-omit-all.test.ts +2 -2
- package/tests/plugin-patch-history-disabled.test.ts +2 -2
- package/tests/plugin-pre-delete.test.ts +1 -1
- package/tests/plugin-pre-save.test.ts +1 -1
- package/tests/plugin.test.ts +2 -2
- package/tsconfig.json +5 -5
- package/vite.config.mts +1 -0
- package/dist/cjs/em.js +0 -9
- package/dist/cjs/em.js.map +0 -1
- package/dist/cjs/helpers.js +0 -43
- package/dist/cjs/helpers.js.map +0 -1
- package/dist/cjs/hooks/delete-hooks.js +0 -46
- package/dist/cjs/hooks/delete-hooks.js.map +0 -1
- package/dist/cjs/hooks/save-hooks.js +0 -30
- package/dist/cjs/hooks/save-hooks.js.map +0 -1
- package/dist/cjs/hooks/update-hooks.js +0 -93
- package/dist/cjs/hooks/update-hooks.js.map +0 -1
- package/dist/cjs/models/History.js +0 -46
- package/dist/cjs/models/History.js.map +0 -1
- package/dist/cjs/patch.js +0 -144
- package/dist/cjs/patch.js.map +0 -1
- package/dist/cjs/plugin.js +0 -51
- package/dist/cjs/plugin.js.map +0 -1
- package/dist/cjs/types/em.d.ts +0 -6
- package/dist/cjs/types/em.d.ts.map +0 -1
- package/dist/cjs/types/helpers.d.ts +0 -6
- package/dist/cjs/types/helpers.d.ts.map +0 -1
- package/dist/cjs/types/hooks/delete-hooks.d.ts +0 -4
- package/dist/cjs/types/hooks/delete-hooks.d.ts.map +0 -1
- package/dist/cjs/types/hooks/save-hooks.d.ts +0 -4
- package/dist/cjs/types/hooks/save-hooks.d.ts.map +0 -1
- package/dist/cjs/types/hooks/update-hooks.d.ts +0 -9
- package/dist/cjs/types/hooks/update-hooks.d.ts.map +0 -1
- package/dist/cjs/types/models/History.d.ts +0 -17
- package/dist/cjs/types/models/History.d.ts.map +0 -1
- package/dist/cjs/types/patch.d.ts +0 -15
- package/dist/cjs/types/patch.d.ts.map +0 -1
- package/dist/cjs/types/plugin.d.ts +0 -23
- package/dist/cjs/types/plugin.d.ts.map +0 -1
- package/dist/cjs/types/types.d.ts +0 -49
- package/dist/cjs/types/types.d.ts.map +0 -1
- package/dist/cjs/types/version.d.ts +0 -4
- package/dist/cjs/types/version.d.ts.map +0 -1
- package/dist/cjs/types.js +0 -3
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/version.js +0 -13
- package/dist/cjs/version.js.map +0 -1
- package/dist/esm/em.js +0 -6
- package/dist/esm/em.js.map +0 -1
- package/dist/esm/helpers.js +0 -37
- package/dist/esm/helpers.js.map +0 -1
- package/dist/esm/hooks/delete-hooks.js +0 -42
- package/dist/esm/hooks/delete-hooks.js.map +0 -1
- package/dist/esm/hooks/save-hooks.js +0 -26
- package/dist/esm/hooks/save-hooks.js.map +0 -1
- package/dist/esm/hooks/update-hooks.js +0 -87
- package/dist/esm/hooks/update-hooks.js.map +0 -1
- package/dist/esm/models/History.js +0 -43
- package/dist/esm/models/History.js.map +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/patch.js +0 -129
- package/dist/esm/patch.js.map +0 -1
- package/dist/esm/plugin.js +0 -45
- package/dist/esm/plugin.js.map +0 -1
- package/dist/esm/types/em.d.ts +0 -6
- package/dist/esm/types/em.d.ts.map +0 -1
- package/dist/esm/types/helpers.d.ts +0 -6
- package/dist/esm/types/helpers.d.ts.map +0 -1
- package/dist/esm/types/hooks/delete-hooks.d.ts +0 -4
- package/dist/esm/types/hooks/delete-hooks.d.ts.map +0 -1
- package/dist/esm/types/hooks/save-hooks.d.ts +0 -4
- package/dist/esm/types/hooks/save-hooks.d.ts.map +0 -1
- package/dist/esm/types/hooks/update-hooks.d.ts +0 -9
- package/dist/esm/types/hooks/update-hooks.d.ts.map +0 -1
- package/dist/esm/types/models/History.d.ts +0 -17
- package/dist/esm/types/models/History.d.ts.map +0 -1
- package/dist/esm/types/patch.d.ts +0 -15
- package/dist/esm/types/patch.d.ts.map +0 -1
- package/dist/esm/types/plugin.d.ts +0 -23
- package/dist/esm/types/plugin.d.ts.map +0 -1
- package/dist/esm/types/types.d.ts +0 -49
- package/dist/esm/types/types.d.ts.map +0 -1
- package/dist/esm/types/version.d.ts +0 -4
- package/dist/esm/types/version.d.ts.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/version.js +0 -9
- package/dist/esm/version.js.map +0 -1
package/src/patch.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import jsonpatch from 'fast-json-patch'
|
|
2
|
-
import
|
|
2
|
+
import _ from 'lodash'
|
|
3
3
|
import omit from 'omit-deep'
|
|
4
4
|
|
|
5
5
|
import type { HydratedDocument, MongooseError, Types } from 'mongoose'
|
|
6
6
|
import type { Metadata, PatchContext, PatchEvent, PluginOptions, User } from './types'
|
|
7
7
|
|
|
8
8
|
import em from './em'
|
|
9
|
-
import { HistoryModel } from './
|
|
9
|
+
import { HistoryModel } from './model'
|
|
10
10
|
|
|
11
11
|
function isPatchHistoryEnabled<T>(opts: PluginOptions<T>, context: PatchContext<T>): boolean {
|
|
12
12
|
return !opts.patchHistoryDisabled && !context.ignorePatchHistory
|
|
@@ -24,28 +24,28 @@ export function getJsonOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>)
|
|
|
24
24
|
|
|
25
25
|
export function getObjectOmit<T>(opts: PluginOptions<T>, doc: HydratedDocument<T>): Partial<T> {
|
|
26
26
|
if (opts.omit) {
|
|
27
|
-
return omit(isFunction(doc?.toObject) ? doc.toObject() : doc, opts.omit)
|
|
27
|
+
return omit(_.isFunction(doc?.toObject) ? doc.toObject() : doc, opts.omit)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return doc
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export async function getUser<T>(opts: PluginOptions<T>): Promise<User | undefined> {
|
|
34
|
-
if (isFunction(opts.getUser)) {
|
|
34
|
+
if (_.isFunction(opts.getUser)) {
|
|
35
35
|
return await opts.getUser()
|
|
36
36
|
}
|
|
37
37
|
return undefined
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export async function getReason<T>(opts: PluginOptions<T>): Promise<string | undefined> {
|
|
41
|
-
if (isFunction(opts.getReason)) {
|
|
41
|
+
if (_.isFunction(opts.getReason)) {
|
|
42
42
|
return await opts.getReason()
|
|
43
43
|
}
|
|
44
44
|
return undefined
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export async function getMetadata<T>(opts: PluginOptions<T>): Promise<Metadata | undefined> {
|
|
48
|
-
if (isFunction(opts.getMetadata)) {
|
|
48
|
+
if (_.isFunction(opts.getMetadata)) {
|
|
49
49
|
return await opts.getMetadata()
|
|
50
50
|
}
|
|
51
51
|
return undefined
|
|
@@ -73,11 +73,11 @@ export async function bulkPatch<T>(opts: PluginOptions<T>, context: PatchContext
|
|
|
73
73
|
const docs = context[docsKey]
|
|
74
74
|
const key = eventKey === 'eventCreated' ? 'doc' : 'oldDoc'
|
|
75
75
|
|
|
76
|
-
if (isEmpty(docs) || (!event && !history)) return
|
|
76
|
+
if (_.isEmpty(docs) || (!event && !history)) return
|
|
77
77
|
|
|
78
78
|
const [user, reason, metadata] = await getData(opts)
|
|
79
79
|
|
|
80
|
-
const chunks = chunk(docs, 1000)
|
|
80
|
+
const chunks = _.chunk(docs, 1000)
|
|
81
81
|
for await (const chunk of chunks) {
|
|
82
82
|
const bulk = []
|
|
83
83
|
|
|
@@ -103,7 +103,7 @@ export async function bulkPatch<T>(opts: PluginOptions<T>, context: PatchContext
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (history && !isEmpty(bulk)) {
|
|
106
|
+
if (history && !_.isEmpty(bulk)) {
|
|
107
107
|
await HistoryModel.bulkWrite(bulk, { ordered: false }).catch((error: MongooseError) => {
|
|
108
108
|
console.error(error.message)
|
|
109
109
|
})
|
|
@@ -120,10 +120,10 @@ export async function updatePatch<T>(opts: PluginOptions<T>, context: PatchConte
|
|
|
120
120
|
|
|
121
121
|
const currentObject = getJsonOmit(opts, current)
|
|
122
122
|
const originalObject = getJsonOmit(opts, original)
|
|
123
|
-
if (isEmpty(originalObject) || isEmpty(currentObject)) return
|
|
123
|
+
if (_.isEmpty(originalObject) || _.isEmpty(currentObject)) return
|
|
124
124
|
|
|
125
125
|
const patch = jsonpatch.compare(originalObject, currentObject, true)
|
|
126
|
-
if (isEmpty(patch)) return
|
|
126
|
+
if (_.isEmpty(patch)) return
|
|
127
127
|
|
|
128
128
|
emitEvent(context, opts.eventUpdated, { oldDoc: original, doc: current, patch })
|
|
129
129
|
|
package/src/version.ts
CHANGED
|
@@ -5,6 +5,8 @@ export const isMongooseLessThan8 = satisfies(mongoose.version, '<8')
|
|
|
5
5
|
export const isMongooseLessThan7 = satisfies(mongoose.version, '<7')
|
|
6
6
|
export const isMongoose6 = satisfies(mongoose.version, '6')
|
|
7
7
|
|
|
8
|
+
/* v8 ignore start */
|
|
8
9
|
if (isMongoose6) {
|
|
9
10
|
mongoose.set('strictQuery', false)
|
|
10
11
|
}
|
|
12
|
+
/* v8 ignore end */
|
package/tests/em.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
+
import { patchEventEmitter } from '../src/index'
|
|
3
4
|
import { emitEvent } from '../src/patch'
|
|
4
|
-
import { patchEventEmitter } from '../src/plugin'
|
|
5
5
|
|
|
6
6
|
describe('em', () => {
|
|
7
7
|
it('should subscribe and count', async () => {
|
package/tests/helpers.test.ts
CHANGED
|
@@ -2,11 +2,11 @@ import ms from 'ms'
|
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import { setPatchHistoryTTL } from '../src/helpers'
|
|
5
|
-
import { HistoryModel } from '../src/
|
|
5
|
+
import { HistoryModel } from '../src/model'
|
|
6
6
|
|
|
7
7
|
import type { Mock, MockInstance } from 'vitest'
|
|
8
8
|
|
|
9
|
-
vi.mock('../src/
|
|
9
|
+
vi.mock('../src/model', () => ({
|
|
10
10
|
HistoryModel: {
|
|
11
11
|
collection: {
|
|
12
12
|
indexes: vi.fn(),
|
package/tests/patch.test.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vites
|
|
|
2
2
|
|
|
3
3
|
import mongoose from 'mongoose'
|
|
4
4
|
|
|
5
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
6
|
import { bulkPatch, getData, getJsonOmit, getMetadata, getReason, getUser, getValue, updatePatch } from '../src/patch'
|
|
6
|
-
import { patchHistoryPlugin } from '../src/plugin'
|
|
7
7
|
|
|
8
8
|
import { USER_DELETED } from './constants/events'
|
|
9
9
|
import { type User, UserSchema } from './schemas/User'
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import mongoose, { Types, model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
8
8
|
import { USER_CREATED } from './constants/events'
|
|
9
9
|
import server from './mongo/server'
|
|
10
10
|
|
|
11
|
-
import { HistoryModel } from '../src/
|
|
11
|
+
import { HistoryModel } from '../src/model'
|
|
12
12
|
import { type User, UserSchema } from './schemas/User'
|
|
13
13
|
|
|
14
14
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn((event: string, data: Record<string, unknown>) => console.log(event, data)) } }))
|
|
@@ -2,8 +2,8 @@ import mongoose, { model } from 'mongoose'
|
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import { toObjectOptions } from '../src/helpers'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
6
|
+
import { HistoryModel } from '../src/model'
|
|
7
7
|
import { isMongooseLessThan7 } from '../src/version'
|
|
8
8
|
|
|
9
9
|
import em from '../src/em'
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import mongoose, { Types, model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
8
8
|
import { USER_UPDATED } from './constants/events'
|
|
9
9
|
import server from './mongo/server'
|
|
10
10
|
|
|
11
|
-
import { HistoryModel } from '../src/
|
|
11
|
+
import { HistoryModel } from '../src/model'
|
|
12
12
|
import { type User, UserSchema } from './schemas/User'
|
|
13
13
|
|
|
14
14
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import mongoose, { model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
|
|
6
6
|
import em from '../src/em'
|
|
7
7
|
import { GLOBAL_CREATED, GLOBAL_DELETED, GLOBAL_UPDATED } from './constants/events'
|
|
8
8
|
import server from './mongo/server'
|
|
9
9
|
|
|
10
|
-
import { HistoryModel } from '../src/
|
|
10
|
+
import { HistoryModel } from '../src/model'
|
|
11
11
|
import { type Product, ProductSchema } from './schemas/Product'
|
|
12
12
|
import { type User, UserSchema } from './schemas/User'
|
|
13
13
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import mongoose, { Types, model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
8
8
|
import server from './mongo/server'
|
|
9
9
|
|
|
10
|
-
import { HistoryModel } from '../src/
|
|
10
|
+
import { HistoryModel } from '../src/model'
|
|
11
11
|
import { type User, UserSchema } from './schemas/User'
|
|
12
12
|
|
|
13
13
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import mongoose, { model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
8
8
|
import server from './mongo/server'
|
|
9
9
|
|
|
10
|
-
import { HistoryModel } from '../src/
|
|
10
|
+
import { HistoryModel } from '../src/model'
|
|
11
11
|
import { type User, UserSchema } from './schemas/User'
|
|
12
12
|
|
|
13
13
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
|
|
6
6
|
import em from '../src/em'
|
|
7
7
|
import { USER_CREATED } from './constants/events'
|
package/tests/plugin.test.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import mongoose, { model } from 'mongoose'
|
|
2
2
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { patchHistoryPlugin } from '../src/
|
|
4
|
+
import { patchHistoryPlugin } from '../src/index'
|
|
5
5
|
import { isMongooseLessThan7 } from '../src/version'
|
|
6
6
|
|
|
7
7
|
import em from '../src/em'
|
|
8
8
|
import { USER_CREATED, USER_DELETED, USER_UPDATED } from './constants/events'
|
|
9
9
|
import server from './mongo/server'
|
|
10
10
|
|
|
11
|
-
import { HistoryModel } from '../src/
|
|
11
|
+
import { HistoryModel } from '../src/model'
|
|
12
12
|
import { type User, UserSchema } from './schemas/User'
|
|
13
13
|
|
|
14
14
|
vi.mock('../src/em', () => ({ default: { emit: vi.fn() } }))
|
package/tsconfig.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
+
"include": ["src"],
|
|
2
3
|
"compilerOptions": {
|
|
3
4
|
"target": "ES2021",
|
|
4
5
|
"lib": ["ES2021"],
|
|
5
|
-
"
|
|
6
|
-
"
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"module": "Preserve",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
7
9
|
"outDir": "dist",
|
|
8
10
|
"strict": true,
|
|
9
11
|
"allowSyntheticDefaultImports": true,
|
|
@@ -27,7 +29,5 @@
|
|
|
27
29
|
"removeComments": true,
|
|
28
30
|
"skipLibCheck": true,
|
|
29
31
|
"sourceMap": true
|
|
30
|
-
}
|
|
31
|
-
"include": ["src"],
|
|
32
|
-
"exclude": ["tests", "dist", "coverage", "node_modules"]
|
|
32
|
+
}
|
|
33
33
|
}
|
package/vite.config.mts
CHANGED
package/dist/cjs/em.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const node_events_1 = tslib_1.__importDefault(require("node:events"));
|
|
5
|
-
class PatchEventEmitter extends node_events_1.default {
|
|
6
|
-
}
|
|
7
|
-
const em = new PatchEventEmitter();
|
|
8
|
-
exports.default = em;
|
|
9
|
-
//# sourceMappingURL=em.js.map
|
package/dist/cjs/em.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"em.js","sourceRoot":"","sources":["../../src/em.ts"],"names":[],"mappings":";;;AAAA,sEAAsC;AAEtC,MAAM,iBAAkB,SAAQ,qBAAY;CAAG;AAC/C,MAAM,EAAE,GAAG,IAAI,iBAAiB,EAAE,CAAA;AAElC,kBAAe,EAAE,CAAA"}
|
package/dist/cjs/helpers.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setPatchHistoryTTL = exports.toObjectOptions = exports.isHookIgnored = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ms_1 = tslib_1.__importDefault(require("ms"));
|
|
6
|
-
const History_1 = require("./models/History");
|
|
7
|
-
const isHookIgnored = (options) => {
|
|
8
|
-
return options.ignoreHook === true || (options.ignoreEvent === true && options.ignorePatchHistory === true);
|
|
9
|
-
};
|
|
10
|
-
exports.isHookIgnored = isHookIgnored;
|
|
11
|
-
exports.toObjectOptions = {
|
|
12
|
-
depopulate: true,
|
|
13
|
-
virtuals: false,
|
|
14
|
-
};
|
|
15
|
-
const setPatchHistoryTTL = async (ttl) => {
|
|
16
|
-
const name = 'createdAt_1_TTL';
|
|
17
|
-
try {
|
|
18
|
-
const indexes = await History_1.HistoryModel.collection.indexes();
|
|
19
|
-
const existingIndex = indexes?.find((index) => index.name === name);
|
|
20
|
-
if (!ttl && existingIndex) {
|
|
21
|
-
await History_1.HistoryModel.collection.dropIndex(name);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const milliseconds = typeof ttl === 'string' ? (0, ms_1.default)(ttl) : ttl;
|
|
25
|
-
if (milliseconds < 1000 && existingIndex) {
|
|
26
|
-
await History_1.HistoryModel.collection.dropIndex(name);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const expireAfterSeconds = milliseconds / 1000;
|
|
30
|
-
if (existingIndex && existingIndex.expireAfterSeconds === expireAfterSeconds) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (existingIndex) {
|
|
34
|
-
await History_1.HistoryModel.collection.dropIndex(name);
|
|
35
|
-
}
|
|
36
|
-
await History_1.HistoryModel.collection.createIndex({ createdAt: 1 }, { expireAfterSeconds, name });
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
console.error("Couldn't create or update index for history collection", err);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
exports.setPatchHistoryTTL = setPatchHistoryTTL;
|
|
43
|
-
//# sourceMappingURL=helpers.js.map
|
package/dist/cjs/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB,8CAA+C;AAIxC,MAAM,aAAa,GAAG,CAAI,OAAwB,EAAW,EAAE;IACpE,OAAO,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,IAAI,IAAI,OAAO,CAAC,kBAAkB,KAAK,IAAI,CAAC,CAAA;AAC7G,CAAC,CAAA;AAFY,QAAA,aAAa,iBAEzB;AAEY,QAAA,eAAe,GAAoB;IAC9C,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,KAAK;CAChB,CAAA;AAEM,MAAM,kBAAkB,GAAG,KAAK,EAAE,GAA4B,EAAiB,EAAE;IACtF,MAAM,IAAI,GAAG,iBAAiB,CAAA;IAC9B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,sBAAY,CAAC,UAAU,CAAC,OAAO,EAAE,CAAA;QACvD,MAAM,aAAa,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;QAGnE,IAAI,CAAC,GAAG,IAAI,aAAa,EAAE,CAAC;YAC1B,MAAM,sBAAY,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YAC7C,OAAM;QACR,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,YAAE,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;QAG5D,IAAI,YAAY,GAAG,IAAI,IAAI,aAAa,EAAE,CAAC;YACzC,MAAM,sBAAY,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YAC7C,OAAM;QACR,CAAC;QAED,MAAM,kBAAkB,GAAG,YAAY,GAAG,IAAI,CAAA;QAE9C,IAAI,aAAa,IAAI,aAAa,CAAC,kBAAkB,KAAK,kBAAkB,EAAE,CAAC;YAE7E,OAAM;QACR,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAElB,MAAM,sBAAY,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAC/C,CAAC;QAGD,MAAM,sBAAY,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3F,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,wDAAwD,EAAE,GAAG,CAAC,CAAA;IAC9E,CAAC;AACH,CAAC,CAAA;AArCY,QAAA,kBAAkB,sBAqC9B"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteHooksInitialize = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
const patch_1 = require("../patch");
|
|
7
|
-
const deleteMethods = ['remove', 'findOneAndDelete', 'findOneAndRemove', 'findByIdAndDelete', 'findByIdAndRemove', 'deleteOne', 'deleteMany'];
|
|
8
|
-
const deleteHooksInitialize = (schema, opts) => {
|
|
9
|
-
schema.pre(deleteMethods, { document: false, query: true }, async function () {
|
|
10
|
-
const options = this.getOptions();
|
|
11
|
-
if ((0, helpers_1.isHookIgnored)(options))
|
|
12
|
-
return;
|
|
13
|
-
const model = this.model;
|
|
14
|
-
const filter = this.getFilter();
|
|
15
|
-
this._context = {
|
|
16
|
-
op: this.op,
|
|
17
|
-
modelName: opts.modelName ?? this.model.modelName,
|
|
18
|
-
collectionName: opts.collectionName ?? this.model.collection.collectionName,
|
|
19
|
-
ignoreEvent: options.ignoreEvent,
|
|
20
|
-
ignorePatchHistory: options.ignorePatchHistory,
|
|
21
|
-
};
|
|
22
|
-
if (['remove', 'deleteMany'].includes(this._context.op) && !options.single) {
|
|
23
|
-
const docs = await model.find(filter).lean().exec();
|
|
24
|
-
if (!(0, lodash_1.isEmpty)(docs)) {
|
|
25
|
-
this._context.deletedDocs = docs;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
const doc = await model.findOne(filter).lean().exec();
|
|
30
|
-
if (!(0, lodash_1.isEmpty)(doc)) {
|
|
31
|
-
this._context.deletedDocs = [doc];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (opts.preDelete && (0, lodash_1.isArray)(this._context.deletedDocs) && !(0, lodash_1.isEmpty)(this._context.deletedDocs)) {
|
|
35
|
-
await opts.preDelete(this._context.deletedDocs);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
schema.post(deleteMethods, { document: false, query: true }, async function () {
|
|
39
|
-
const options = this.getOptions();
|
|
40
|
-
if ((0, helpers_1.isHookIgnored)(options))
|
|
41
|
-
return;
|
|
42
|
-
await (0, patch_1.deletePatch)(opts, this._context);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
exports.deleteHooksInitialize = deleteHooksInitialize;
|
|
46
|
-
//# sourceMappingURL=delete-hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delete-hooks.js","sourceRoot":"","sources":["../../../src/hooks/delete-hooks.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AAEzC,wCAA0C;AAC1C,oCAAsC;AAKtC,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAA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EAAE,CAAC,IAAI,EAAE,CAAA;YACxD,IAAI,CAAC,IAAA,gBAAO,EAAC,GAAG,CAAC,EAAE,CAAC;gBAClB,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,GAAG,CAA0B,CAAA;YAC5D,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,IAAI,IAAA,gBAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAA,gBAAO,EAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAChG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;QACjD,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,aAA0C,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK;QAC7F,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;QACjC,IAAI,IAAA,uBAAa,EAAC,OAAO,CAAC;YAAE,OAAM;QAElC,MAAM,IAAA,mBAAW,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAvCY,QAAA,qBAAqB,yBAuCjC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saveHooksInitialize = void 0;
|
|
4
|
-
const helpers_1 = require("../helpers");
|
|
5
|
-
const patch_1 = require("../patch");
|
|
6
|
-
const saveHooksInitialize = (schema, opts) => {
|
|
7
|
-
schema.pre('save', async function () {
|
|
8
|
-
if (this.constructor.name !== 'model')
|
|
9
|
-
return;
|
|
10
|
-
const current = this.toObject(helpers_1.toObjectOptions);
|
|
11
|
-
const model = this.constructor;
|
|
12
|
-
const context = {
|
|
13
|
-
op: this.isNew ? 'create' : 'update',
|
|
14
|
-
modelName: opts.modelName ?? model.modelName,
|
|
15
|
-
collectionName: opts.collectionName ?? model.collection.collectionName,
|
|
16
|
-
createdDocs: [current],
|
|
17
|
-
};
|
|
18
|
-
if (this.isNew) {
|
|
19
|
-
await (0, patch_1.createPatch)(opts, context);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
const original = await model.findById(current._id).lean().exec();
|
|
23
|
-
if (original) {
|
|
24
|
-
await (0, patch_1.updatePatch)(opts, context, current, original);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.saveHooksInitialize = saveHooksInitialize;
|
|
30
|
-
//# sourceMappingURL=save-hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"save-hooks.js","sourceRoot":"","sources":["../../../src/hooks/save-hooks.ts"],"names":[],"mappings":";;;AAAA,wCAA4C;AAC5C,oCAAmD;AAK5C,MAAM,mBAAmB,GAAG,CAAI,MAAiB,EAAE,IAAsB,EAAQ,EAAE;IACxF,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK;QACtB,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,OAAO;YAAE,OAAM;QAE7C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAe,CAAwB,CAAA;QACrE,MAAM,KAAK,GAAG,IAAI,CAAC,WAAuB,CAAA;QAE1C,MAAM,OAAO,GAAoB;YAC/B,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;YACpC,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS;YAC5C,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc;YACtE,WAAW,EAAE,CAAC,OAAO,CAAC;SACvB,CAAA;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,IAAA,mBAAW,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;YAChE,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,IAAA,mBAAW,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAA+B,CAAC,CAAA;YAC5E,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAvBY,QAAA,mBAAmB,uBAuB/B"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateHooksInitialize = exports.splitUpdateAndCommands = exports.assignUpdate = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const power_assign_1 = require("power-assign");
|
|
6
|
-
const helpers_1 = require("../helpers");
|
|
7
|
-
const patch_1 = require("../patch");
|
|
8
|
-
const updateMethods = ['update', 'updateOne', 'replaceOne', 'updateMany', 'findOneAndUpdate', 'findOneAndReplace', 'findByIdAndUpdate'];
|
|
9
|
-
const assignUpdate = (document, update, commands) => {
|
|
10
|
-
let updated = (0, power_assign_1.assign)(document.toObject(helpers_1.toObjectOptions), update);
|
|
11
|
-
(0, lodash_1.forEach)(commands, (command) => {
|
|
12
|
-
try {
|
|
13
|
-
updated = (0, power_assign_1.assign)(updated, command);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const doc = document.set(updated).toObject(helpers_1.toObjectOptions);
|
|
19
|
-
if (update.createdAt)
|
|
20
|
-
doc.createdAt = update.createdAt;
|
|
21
|
-
return doc;
|
|
22
|
-
};
|
|
23
|
-
exports.assignUpdate = assignUpdate;
|
|
24
|
-
const splitUpdateAndCommands = (updateQuery) => {
|
|
25
|
-
let update = {};
|
|
26
|
-
const commands = [];
|
|
27
|
-
if (!(0, lodash_1.isEmpty)(updateQuery) && !(0, lodash_1.isArray)(updateQuery) && (0, lodash_1.isObjectLike)(updateQuery)) {
|
|
28
|
-
update = (0, lodash_1.cloneDeep)(updateQuery);
|
|
29
|
-
const keysWithDollarSign = (0, lodash_1.keys)(update).filter((key) => key.startsWith('$'));
|
|
30
|
-
if (!(0, lodash_1.isEmpty)(keysWithDollarSign)) {
|
|
31
|
-
(0, lodash_1.forEach)(keysWithDollarSign, (key) => {
|
|
32
|
-
commands.push({ [key]: update[key] });
|
|
33
|
-
delete update[key];
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return { update, commands };
|
|
38
|
-
};
|
|
39
|
-
exports.splitUpdateAndCommands = splitUpdateAndCommands;
|
|
40
|
-
const updateHooksInitialize = (schema, opts) => {
|
|
41
|
-
schema.pre(updateMethods, async function () {
|
|
42
|
-
const options = this.getOptions();
|
|
43
|
-
if ((0, helpers_1.isHookIgnored)(options))
|
|
44
|
-
return;
|
|
45
|
-
const model = this.model;
|
|
46
|
-
const filter = this.getFilter();
|
|
47
|
-
const count = await this.model.countDocuments(filter).exec();
|
|
48
|
-
this._context = {
|
|
49
|
-
op: this.op,
|
|
50
|
-
modelName: opts.modelName ?? this.model.modelName,
|
|
51
|
-
collectionName: opts.collectionName ?? this.model.collection.collectionName,
|
|
52
|
-
isNew: Boolean(options.upsert) && count === 0,
|
|
53
|
-
ignoreEvent: options.ignoreEvent,
|
|
54
|
-
ignorePatchHistory: options.ignorePatchHistory,
|
|
55
|
-
};
|
|
56
|
-
const updateQuery = this.getUpdate();
|
|
57
|
-
const { update, commands } = (0, exports.splitUpdateAndCommands)(updateQuery);
|
|
58
|
-
const cursor = model.find(filter).cursor();
|
|
59
|
-
await cursor.eachAsync(async (doc) => {
|
|
60
|
-
const origDoc = doc.toObject(helpers_1.toObjectOptions);
|
|
61
|
-
await (0, patch_1.updatePatch)(opts, this._context, (0, exports.assignUpdate)(doc, update, commands), origDoc);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
schema.post(updateMethods, async function () {
|
|
65
|
-
const options = this.getOptions();
|
|
66
|
-
if ((0, helpers_1.isHookIgnored)(options))
|
|
67
|
-
return;
|
|
68
|
-
if (!this._context.isNew)
|
|
69
|
-
return;
|
|
70
|
-
const model = this.model;
|
|
71
|
-
const updateQuery = this.getUpdate();
|
|
72
|
-
const { update, commands } = (0, exports.splitUpdateAndCommands)(updateQuery);
|
|
73
|
-
let current = null;
|
|
74
|
-
const filter = this.getFilter();
|
|
75
|
-
const combined = (0, exports.assignUpdate)(model.hydrate({}), update, commands);
|
|
76
|
-
if (!(0, lodash_1.isEmpty)(update) && !current) {
|
|
77
|
-
current = (await model.findOne(update).sort('desc').lean().exec());
|
|
78
|
-
}
|
|
79
|
-
if (!(0, lodash_1.isEmpty)(combined) && !current) {
|
|
80
|
-
current = (await model.findOne(combined).sort('desc').lean().exec());
|
|
81
|
-
}
|
|
82
|
-
if (!(0, lodash_1.isEmpty)(filter) && !current) {
|
|
83
|
-
console.log('filter', filter);
|
|
84
|
-
current = (await model.findOne(filter).sort('desc').lean().exec());
|
|
85
|
-
}
|
|
86
|
-
if (current) {
|
|
87
|
-
this._context.createdDocs = [current];
|
|
88
|
-
await (0, patch_1.createPatch)(opts, this._context);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
exports.updateHooksInitialize = updateHooksInitialize;
|
|
93
|
-
//# sourceMappingURL=update-hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update-hooks.js","sourceRoot":"","sources":["../../../src/hooks/update-hooks.ts"],"names":[],"mappings":";;;AAAA,mCAAiF;AACjF,+CAAqC;AAErC,wCAA2D;AAC3D,oCAAmD;AAKnD,MAAM,aAAa,GAAG,CAAC,QAAQ,EAAE,WA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C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAwB,CAAA;QAC3F,CAAC;QAED,IAAI,CAAC,IAAA,gBAAO,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAwB,CAAA;QAC7F,CAAC;QAED,IAAI,CAAC,IAAA,gBAAO,EAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC7B,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAwB,CAAA;QAC3F,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,OAAO,CAA0B,CAAA;YAE9D,MAAM,IAAA,mBAAW,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QACxC,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA5DY,QAAA,qBAAqB,yBA4DjC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HistoryModel = exports.HistorySchema = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
exports.HistorySchema = new mongoose_1.Schema({
|
|
6
|
-
op: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: true,
|
|
9
|
-
},
|
|
10
|
-
modelName: {
|
|
11
|
-
type: String,
|
|
12
|
-
required: true,
|
|
13
|
-
},
|
|
14
|
-
collectionName: {
|
|
15
|
-
type: String,
|
|
16
|
-
required: true,
|
|
17
|
-
},
|
|
18
|
-
collectionId: {
|
|
19
|
-
type: mongoose_1.Schema.Types.ObjectId,
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
doc: {
|
|
23
|
-
type: Object,
|
|
24
|
-
},
|
|
25
|
-
patch: {
|
|
26
|
-
type: Array,
|
|
27
|
-
},
|
|
28
|
-
user: {
|
|
29
|
-
type: Object,
|
|
30
|
-
},
|
|
31
|
-
reason: {
|
|
32
|
-
type: String,
|
|
33
|
-
},
|
|
34
|
-
metadata: {
|
|
35
|
-
type: Object,
|
|
36
|
-
},
|
|
37
|
-
version: {
|
|
38
|
-
type: Number,
|
|
39
|
-
min: 0,
|
|
40
|
-
default: 0,
|
|
41
|
-
},
|
|
42
|
-
}, { timestamps: true });
|
|
43
|
-
exports.HistorySchema.index({ collectionId: 1, version: -1 });
|
|
44
|
-
exports.HistorySchema.index({ op: 1, modelName: 1, collectionName: 1, collectionId: 1, reason: 1, version: 1 });
|
|
45
|
-
exports.HistoryModel = (0, mongoose_1.model)('History', exports.HistorySchema, 'history');
|
|
46
|
-
//# sourceMappingURL=History.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"History.js","sourceRoot":"","sources":["../../../src/models/History.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAI3B,QAAA,aAAa,GAAG,IAAI,iBAAM,CACrC;IACE,EAAE,EAAE;QACF,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,QAAQ;QAC3B,QAAQ,EAAE,IAAI;KACf;IACD,GAAG,EAAE;QACH,IAAI,EAAE,MAAM;KACb;IACD,KAAK,EAAE;QACL,IAAI,EAAE,KAAK;KACZ;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;KACb;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;KACb;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;KACb;IACD,OAAO,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;KACX;CACF,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;AAED,qBAAa,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;AACrD,qBAAa,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;AAE1F,QAAA,YAAY,GAAG,IAAA,gBAAK,EAAU,SAAS,EAAE,qBAAa,EAAE,SAAS,CAAC,CAAA"}
|