@strapi/database 5.59.0 → 5.60.0
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/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/entity-manager/index.js +94 -0
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +95 -1
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/regular-relations.d.ts.map +1 -1
- package/dist/entity-manager/regular-relations.js +6 -1
- package/dist/entity-manager/regular-relations.js.map +1 -1
- package/dist/entity-manager/regular-relations.mjs +8 -3
- package/dist/entity-manager/regular-relations.mjs.map +1 -1
- package/dist/entity-manager/types.d.ts +3 -0
- package/dist/entity-manager/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/lifecycles/index.d.ts +1 -0
- package/dist/lifecycles/index.d.ts.map +1 -1
- package/dist/lifecycles/index.js +29 -1
- package/dist/lifecycles/index.js.map +1 -1
- package/dist/lifecycles/index.mjs +29 -1
- package/dist/lifecycles/index.mjs.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.js +2 -2
- package/dist/lifecycles/subscribers/timestamps.js.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.mjs +2 -2
- package/dist/lifecycles/subscribers/timestamps.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model } from './types';\nimport { createRepairManager, type RepairManager } from './repairs';\nimport { installPoolDiagnostics, type PoolDiagnostics } from './pool-diagnostics';\nimport { withStrapiKnexLog } from './utils/knex-log';\n\nexport { isKnexQuery } from './utils/knex';\nexport { isDatabaseClientKind } from './connection';\nexport { attributeNaming } from './metadata';\nexport type { AttributeNaming, Meta } from './metadata';\nexport type {\n AttributeRenamesOperation,\n Migration,\n BuiltMigrationFile,\n MigrationFileBuilder,\n MigrationFileFormat,\n MigrationFileOperation,\n} from './migrations';\nexport type { Event } from './lifecycles';\nexport type { Attribute, Model, JoinTable } from './types';\nexport type { AttributeRenameHandler, AttributeRenames } from './schema';\nexport type { Identifiers } from './utils/identifiers';\nexport { POOL_TIMEOUT_CODE } from './pool-diagnostics';\nexport type {\n EventLoopDelay,\n PoolDiagnostics,\n PoolState,\n PoolTimeoutDetails,\n} from './pool-diagnostics';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n /**\n * Describe the pool on knex connection pool timeouts (details on the error, a docs link, one\n * warning block per 30 s). Defaults to true; false leaves knex's error untouched. Must be a\n * boolean (for example `env.bool('DATABASE_POOL_TIMEOUT_DIAGNOSTICS', true)`): a string is not\n * read as false.\n */\n poolTimeoutDiagnostics?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n /** Lifecycle phase of the host application, e.g. \"boot\" or \"runtime\", for pool timeout reports. */\n getPhase?: () => string | undefined;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n /** Set unless `settings.poolTimeoutDiagnostics` is false or the install failed. */\n private poolDiagnostics?: PoolDiagnostics;\n\n private phase?: string;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...config.settings,\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(withStrapiKnexLog(knexConfig, this.logger), {\n pool: { afterCreate: afterCreate(this) },\n });\n\n if (this.config.settings.poolTimeoutDiagnostics !== false) {\n try {\n this.poolDiagnostics = installPoolDiagnostics(this.connection, {\n logger: { warn: (message) => this.logger.warn(message) },\n getPhase: () => this.phase ?? this.config.getPhase?.(),\n });\n } catch (error) {\n // Diagnostics are optional: failing to install them must not stop the application booting\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.debug(`[database] pool timeout diagnostics not installed: ${reason}`);\n }\n }\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n // release it straight away, otherwise it holds a pool slot for the life of the process\n const conn = await this.connection.client.acquireConnection();\n await this.connection.client.releaseConnection(conn);\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n /**\n * Labels pool timeout reports raised while `fn` runs, for example \"schema sync\". Nested calls\n * restore the outer label. Calls that overlap without nesting can restore the wrong label; core\n * only nests them (schema sync, then a migration).\n *\n * The label is process-wide, not per call: a call made at runtime relabels every concurrent\n * timeout report until it returns. It is meant for boot-time work (schema sync, migrations).\n *\n * @internal\n */\n async runInPhase<T>(phase: string, fn: () => Promise<T>): Promise<T> {\n const previous = this.phase;\n this.phase = phase;\n\n try {\n return await fn();\n } finally {\n this.phase = previous;\n }\n }\n\n /**\n * Run work inside a DB transaction. On a fulfilled callback, the transaction\n * is committed; on rejection, it is rolled back. The callback receives Knex\n * `commit` and `rollback` helpers: if you call `rollback` and return without\n * throwing, the implementation avoids attempting a second `commit` on an\n * already-finalised transactor.\n */\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n try {\n await this.lifecycles.clear();\n } finally {\n this.poolDiagnostics?.dispose();\n }\n\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","conn","acquireConnection","releaseConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","runInPhase","phase","fn","previous","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","poolDiagnostics","dispose","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","createMetadata","createConnection","withStrapiKnexLog","pool","poolTimeoutDiagnostics","installPoolDiagnostics","message","getPhase","reason","String","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwEA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA4FJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MAAM,EAAuB,EAAE;QAC1C,IAAI,OAAO,IAAI,CAACC,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;AAC3D;;;;;;;;;AASC,UACD,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,4CAAA,CAAA;;YAGlB,IAAI,IAAI,CAACH,MAAM,CAACC,UAAU,CAACG,MAAM,KAAK,QAAA,EAAU;AAC9C,gBAAA,MAAM,IAAI,CAACH,UAAU,CAACI,GAAG,C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AA;AACxC,IAAA;AA8KF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model } from './types';\nimport { createRepairManager, type RepairManager } from './repairs';\nimport { installPoolDiagnostics, type PoolDiagnostics } from './pool-diagnostics';\nimport { withStrapiKnexLog } from './utils/knex-log';\n\nexport { isKnexQuery } from './utils/knex';\nexport { isDatabaseClientKind } from './connection';\nexport { attributeNaming } from './metadata';\nexport { createField } from './fields';\nexport type { AttributeNaming, Meta } from './metadata';\nexport type {\n AttributeRenamesOperation,\n Migration,\n BuiltMigrationFile,\n MigrationFileBuilder,\n MigrationFileFormat,\n MigrationFileOperation,\n} from './migrations';\nexport type { Event } from './lifecycles';\nexport type { Attribute, Model, JoinTable } from './types';\nexport type { AttributeRenameHandler, AttributeRenames } from './schema';\nexport type { Identifiers } from './utils/identifiers';\nexport { POOL_TIMEOUT_CODE } from './pool-diagnostics';\nexport type {\n EventLoopDelay,\n PoolDiagnostics,\n PoolState,\n PoolTimeoutDetails,\n} from './pool-diagnostics';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n /**\n * Describe the pool on knex connection pool timeouts (details on the error, a docs link, one\n * warning block per 30 s). Defaults to true; false leaves knex's error untouched. Must be a\n * boolean (for example `env.bool('DATABASE_POOL_TIMEOUT_DIAGNOSTICS', true)`): a string is not\n * read as false.\n */\n poolTimeoutDiagnostics?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n /** Lifecycle phase of the host application, e.g. \"boot\" or \"runtime\", for pool timeout reports. */\n getPhase?: () => string | undefined;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n /** Set unless `settings.poolTimeoutDiagnostics` is false or the install failed. */\n private poolDiagnostics?: PoolDiagnostics;\n\n private phase?: string;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...config.settings,\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(withStrapiKnexLog(knexConfig, this.logger), {\n pool: { afterCreate: afterCreate(this) },\n });\n\n if (this.config.settings.poolTimeoutDiagnostics !== false) {\n try {\n this.poolDiagnostics = installPoolDiagnostics(this.connection, {\n logger: { warn: (message) => this.logger.warn(message) },\n getPhase: () => this.phase ?? this.config.getPhase?.(),\n });\n } catch (error) {\n // Diagnostics are optional: failing to install them must not stop the application booting\n const reason = error instanceof Error ? error.message : String(error);\n this.logger.debug(`[database] pool timeout diagnostics not installed: ${reason}`);\n }\n }\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n // release it straight away, otherwise it holds a pool slot for the life of the process\n const conn = await this.connection.client.acquireConnection();\n await this.connection.client.releaseConnection(conn);\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n /**\n * Labels pool timeout reports raised while `fn` runs, for example \"schema sync\". Nested calls\n * restore the outer label. Calls that overlap without nesting can restore the wrong label; core\n * only nests them (schema sync, then a migration).\n *\n * The label is process-wide, not per call: a call made at runtime relabels every concurrent\n * timeout report until it returns. It is meant for boot-time work (schema sync, migrations).\n *\n * @internal\n */\n async runInPhase<T>(phase: string, fn: () => Promise<T>): Promise<T> {\n const previous = this.phase;\n this.phase = phase;\n\n try {\n return await fn();\n } finally {\n this.phase = previous;\n }\n }\n\n /**\n * Run work inside a DB transaction. On a fulfilled callback, the transaction\n * is committed; on rejection, it is rolled back. The callback receives Knex\n * `commit` and `rollback` helpers: if you call `rollback` and return without\n * throwing, the implementation avoids attempting a second `commit` on an\n * already-finalised transactor.\n */\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n try {\n await this.lifecycles.clear();\n } finally {\n this.poolDiagnostics?.dispose();\n }\n\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","conn","acquireConnection","releaseConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","runInPhase","phase","fn","previous","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","poolDiagnostics","dispose","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","createMetadata","createConnection","withStrapiKnexLog","pool","poolTimeoutDiagnostics","installPoolDiagnostics","message","getPhase","reason","String","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyEA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA4FJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MA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GuC,oBAAAA,CAAqB,IAAI,CAAA;AAEvC,QAAA,IAAI,CAACC,UAAU,GAAGC,wBAAAA,CAAyB,IAAI,CAAA;AAC/C,QAAA,IAAI,CAACxB,UAAU,GAAGyB,wBAAAA,CAAyB,IAAI,CAAA;AAE/C,QAAA,IAAI,CAACjE,aAAa,GAAGkE,mBAAAA,CAAoB,IAAI,CAAA;AAE7C,QAAA,IAAI,CAACC,MAAM,GAAGC,mBAAAA,CAAoB,IAAI,CAAA;AACxC,IAAA;AA8KF;;;;"}
|
|
@@ -11,6 +11,7 @@ export interface LifecycleProvider {
|
|
|
11
11
|
subscribe(subscriber: Subscriber): () => void;
|
|
12
12
|
clear(): void;
|
|
13
13
|
run(action: Action, uid: string, properties: Properties, states?: States): Promise<States>;
|
|
14
|
+
hasSubscribers(action: Action, uid: string): boolean;
|
|
14
15
|
createEvent(action: Action, uid: string, properties: Properties, state: State): Event;
|
|
15
16
|
disable(): void;
|
|
16
17
|
enable(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lifecycles/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAEnC,mBAAmB,SAAS,CAAC;AAE7B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAE5C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI,CAAC;IAC9C,KAAK,IAAI,I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AG,OAAO,CAAC;IACrD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;IACtF,OAAO,IAAI,IAAI,CAAC;IAChB,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,eAAO,MAAM,wBAAwB,GAAI,IAAI,QAAQ,KAAG,iBAoHvD,CAAC"}
|
package/dist/lifecycles/index.js
CHANGED
|
@@ -15,7 +15,12 @@ const createLifecyclesProvider = (db)=>{
|
|
|
15
15
|
subscribe (subscriber) {
|
|
16
16
|
assert.strict(index.isValidSubscriber(subscriber), 'Invalid subscriber. Expected function or object');
|
|
17
17
|
subscribers.push(subscriber);
|
|
18
|
-
return ()=>
|
|
18
|
+
return ()=>{
|
|
19
|
+
const index = subscribers.indexOf(subscriber);
|
|
20
|
+
if (index >= 0) {
|
|
21
|
+
subscribers.splice(index, 1);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
19
24
|
},
|
|
20
25
|
clear () {
|
|
21
26
|
subscribers = [];
|
|
@@ -26,6 +31,29 @@ const createLifecyclesProvider = (db)=>{
|
|
|
26
31
|
enable () {
|
|
27
32
|
isLifecycleHooksDisabled = false;
|
|
28
33
|
},
|
|
34
|
+
/**
|
|
35
|
+
* Whether running `action` on `uid` would reach anyone: a lifecycle declared on the model, a
|
|
36
|
+
* subscriber registered for that model or for every model, or a subscriber function. The
|
|
37
|
+
* provider's own timestamps subscriber does not count: it only stamps the data of a write that
|
|
38
|
+
* is about to happen and observes nothing.
|
|
39
|
+
*/ hasSubscribers (action, uid) {
|
|
40
|
+
if (isLifecycleHooksDisabled) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return subscribers.some((subscriber)=>{
|
|
44
|
+
if (subscriber === timestamps.timestampsLifecyclesSubscriber) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (subscriber === modelsLifecycles.modelsLifecyclesSubscriber) {
|
|
48
|
+
const model = db.metadata.get(uid);
|
|
49
|
+
return Boolean(model.lifecycles && action in model.lifecycles);
|
|
50
|
+
}
|
|
51
|
+
if (typeof subscriber === 'function') {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return action in subscriber && (!subscriber.models || subscriber.models.includes(uid));
|
|
55
|
+
});
|
|
56
|
+
},
|
|
29
57
|
createEvent (action, uid, properties, state) {
|
|
30
58
|
const model = db.metadata.get(uid);
|
|
31
59
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/lifecycles/index.ts"],"sourcesContent":["import { strict as assert } from 'assert';\n\nimport * as subscriberUtils from './subscribers';\n\nimport type { Action, Event, Params, Subscriber } from './types';\nimport type { Database } from '..';\n\nexport type * from './types';\n\nexport type State = Record<string, unknown>;\nexport type States = Map<Subscriber, State>;\n\nexport interface Properties {\n params: Params;\n result?: unknown;\n}\n\nexport interface LifecycleProvider {\n subscribe(subscriber: Subscriber): () => void;\n clear(): void;\n run(action: Action, uid: string, properties: Properties, states?: States): Promise<States>;\n createEvent(action: Action, uid: string, properties: Properties, state: State): Event;\n disable(): void;\n enable(): void;\n}\n\nexport const createLifecyclesProvider = (db: Database): LifecycleProvider => {\n let subscribers = [\n subscriberUtils.timestampsLifecyclesSubscriber,\n subscriberUtils.modelsLifecyclesSubscriber,\n ];\n\n let isLifecycleHooksDisabled = false;\n\n return {\n subscribe(subscriber) {\n assert(\n subscriberUtils.isValidSubscriber(subscriber),\n 'Invalid subscriber. Expected function or object'\n );\n\n subscribers.push(subscriber);\n\n return () => subscribers.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/lifecycles/index.ts"],"sourcesContent":["import { strict as assert } from 'assert';\n\nimport * as subscriberUtils from './subscribers';\n\nimport type { Action, Event, Params, Subscriber } from './types';\nimport type { Database } from '..';\n\nexport type * from './types';\n\nexport type State = Record<string, unknown>;\nexport type States = Map<Subscriber, State>;\n\nexport interface Properties {\n params: Params;\n result?: unknown;\n}\n\nexport interface LifecycleProvider {\n subscribe(subscriber: Subscriber): () => void;\n clear(): void;\n run(action: Action, uid: string, properties: Properties, states?: States): Promise<States>;\n hasSubscribers(action: Action, uid: string): boolean;\n createEvent(action: Action, uid: string, properties: Properties, state: State): Event;\n disable(): void;\n enable(): void;\n}\n\nexport const createLifecyclesProvider = (db: Database): LifecycleProvider => {\n let subscribers = [\n subscriberUtils.timestampsLifecyclesSubscriber,\n subscriberUtils.modelsLifecyclesSubscriber,\n ];\n\n let isLifecycleHooksDisabled = false;\n\n return {\n subscribe(subscriber) {\n assert(\n subscriberUtils.isValidSubscriber(subscriber),\n 'Invalid subscriber. Expected function or object'\n );\n\n subscribers.push(subscriber);\n\n return () => {\n const index = subscribers.indexOf(subscriber);\n\n if (index >= 0) {\n subscribers.splice(index, 1);\n }\n };\n },\n\n clear() {\n subscribers = [];\n },\n\n disable() {\n isLifecycleHooksDisabled = true;\n },\n\n enable() {\n isLifecycleHooksDisabled = false;\n },\n\n /**\n * Whether running `action` on `uid` would reach anyone: a lifecycle declared on the model, a\n * subscriber registered for that model or for every model, or a subscriber function. The\n * provider's own timestamps subscriber does not count: it only stamps the data of a write that\n * is about to happen and observes nothing.\n */\n hasSubscribers(action, uid) {\n if (isLifecycleHooksDisabled) {\n return false;\n }\n\n return subscribers.some((subscriber) => {\n if (subscriber === subscriberUtils.timestampsLifecyclesSubscriber) {\n return false;\n }\n\n if (subscriber === subscriberUtils.modelsLifecyclesSubscriber) {\n const model = db.metadata.get(uid);\n\n return Boolean(model.lifecycles && action in model.lifecycles);\n }\n\n if (typeof subscriber === 'function') {\n return true;\n }\n\n return action in subscriber && (!subscriber.models || subscriber.models.includes(uid));\n });\n },\n\n createEvent(action, uid, properties, state): Event {\n const model = db.metadata.get(uid);\n\n return {\n action,\n model,\n state,\n ...properties,\n };\n },\n\n /**\n * @param {string} action\n * @param {string} uid\n * @param {{ params?: any, result?: any }} properties\n * @param {Map<any, any>} states\n */\n async run(action, uid, properties, states = new Map()) {\n if (isLifecycleHooksDisabled) return states;\n for (let i = 0; i < subscribers.length; i += 1) {\n const subscriber = subscribers[i];\n if (typeof subscriber === 'function') {\n const state = states.get(subscriber) || {};\n const event = this.createEvent(action, uid, properties, state);\n await subscriber(event);\n if (event.state) {\n states.set(subscriber, event.state || state);\n }\n continue;\n }\n\n const hasAction = action in subscriber;\n const hasModel = !subscriber.models || subscriber.models.includes(uid);\n\n if (hasAction && hasModel) {\n const state = states.get(subscriber) || {};\n const event = this.createEvent(action, uid, properties, state);\n\n await subscriber[action]?.(event);\n if (event.state) {\n states.set(subscriber, event.state);\n }\n }\n }\n\n return states;\n },\n };\n};\n"],"names":["createLifecyclesProvider","db","subscribers","subscriberUtils","isLifecycleHooksDisabled","subscribe","subscriber","assert","push","index","indexOf","splice","clear","disable","enable","hasSubscribers","action","uid","some","model","metadata","get","Boolean","lifecycles","models","includes","createEvent","properties","state","run","states","Map","i","length","event","set","hasAction","hasModel"],"mappings":";;;;;;;AA2BO,MAAMA,2BAA2B,CAACC,EAAAA,GAAAA;AACvC,IAAA,IAAIC,WAAAA,GAAc;AAChBC,QAAAA,yCAA8C;AAC9CA,QAAAA;AACD,KAAA;AAED,IAAA,IAAIC,wBAAAA,GAA2B,KAAA;IAE/B,OAAO;AACLC,QAAAA,SAAAA,CAAAA,CAAUC,UAAU,EAAA;YAClBC,aAAAA,CACEJ,uBAAiC,CAACG,UAAAA,CAAAA,EAClC,iDAAA,CAAA;AAGFJ,YAAAA,WAAAA,CAAYM,IAAI,CAACF,UAAAA,CAAAA;YAEjB,OAAO,IAAA;gBACL,MAAMG,KAAAA,GAAQP,WAAAA,CAAYQ,OAAO,CAACJ,UAAAA,CAAAA;AAElC,gBAAA,IAAIG,SAAS,CAAA,EAAG;oBACdP,WAAAA,CAAYS,MAAM,CAACF,KAAAA,EAAO,CAAA,CAAA;AAC5B,gBAAA;AACF,YAAA,CAAA;AACF,QAAA,CAAA;AAEAG,QAAA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AA,CAAAA;oBAExD,MAAMtB,UAAU,CAACU,MAAAA,CAAO,GAAGkB,KAAAA,CAAAA;oBAC3B,IAAIA,KAAAA,CAAMN,KAAK,EAAE;AACfE,wBAAAA,MAAAA,CAAOK,GAAG,CAAC7B,UAAAA,EAAY4B,KAAAA,CAAMN,KAAK,CAAA;AACpC,oBAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOE,MAAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -13,7 +13,12 @@ const createLifecyclesProvider = (db)=>{
|
|
|
13
13
|
subscribe (subscriber) {
|
|
14
14
|
strict(isValidSubscriber(subscriber), 'Invalid subscriber. Expected function or object');
|
|
15
15
|
subscribers.push(subscriber);
|
|
16
|
-
return ()=>
|
|
16
|
+
return ()=>{
|
|
17
|
+
const index = subscribers.indexOf(subscriber);
|
|
18
|
+
if (index >= 0) {
|
|
19
|
+
subscribers.splice(index, 1);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
17
22
|
},
|
|
18
23
|
clear () {
|
|
19
24
|
subscribers = [];
|
|
@@ -24,6 +29,29 @@ const createLifecyclesProvider = (db)=>{
|
|
|
24
29
|
enable () {
|
|
25
30
|
isLifecycleHooksDisabled = false;
|
|
26
31
|
},
|
|
32
|
+
/**
|
|
33
|
+
* Whether running `action` on `uid` would reach anyone: a lifecycle declared on the model, a
|
|
34
|
+
* subscriber registered for that model or for every model, or a subscriber function. The
|
|
35
|
+
* provider's own timestamps subscriber does not count: it only stamps the data of a write that
|
|
36
|
+
* is about to happen and observes nothing.
|
|
37
|
+
*/ hasSubscribers (action, uid) {
|
|
38
|
+
if (isLifecycleHooksDisabled) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return subscribers.some((subscriber)=>{
|
|
42
|
+
if (subscriber === timestampsLifecyclesSubscriber) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (subscriber === modelsLifecyclesSubscriber) {
|
|
46
|
+
const model = db.metadata.get(uid);
|
|
47
|
+
return Boolean(model.lifecycles && action in model.lifecycles);
|
|
48
|
+
}
|
|
49
|
+
if (typeof subscriber === 'function') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return action in subscriber && (!subscriber.models || subscriber.models.includes(uid));
|
|
53
|
+
});
|
|
54
|
+
},
|
|
27
55
|
createEvent (action, uid, properties, state) {
|
|
28
56
|
const model = db.metadata.get(uid);
|
|
29
57
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/lifecycles/index.ts"],"sourcesContent":["import { strict as assert } from 'assert';\n\nimport * as subscriberUtils from './subscribers';\n\nimport type { Action, Event, Params, Subscriber } from './types';\nimport type { Database } from '..';\n\nexport type * from './types';\n\nexport type State = Record<string, unknown>;\nexport type States = Map<Subscriber, State>;\n\nexport interface Properties {\n params: Params;\n result?: unknown;\n}\n\nexport interface LifecycleProvider {\n subscribe(subscriber: Subscriber): () => void;\n clear(): void;\n run(action: Action, uid: string, properties: Properties, states?: States): Promise<States>;\n createEvent(action: Action, uid: string, properties: Properties, state: State): Event;\n disable(): void;\n enable(): void;\n}\n\nexport const createLifecyclesProvider = (db: Database): LifecycleProvider => {\n let subscribers = [\n subscriberUtils.timestampsLifecyclesSubscriber,\n subscriberUtils.modelsLifecyclesSubscriber,\n ];\n\n let isLifecycleHooksDisabled = false;\n\n return {\n subscribe(subscriber) {\n assert(\n subscriberUtils.isValidSubscriber(subscriber),\n 'Invalid subscriber. Expected function or object'\n );\n\n subscribers.push(subscriber);\n\n return () => subscribers.
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/lifecycles/index.ts"],"sourcesContent":["import { strict as assert } from 'assert';\n\nimport * as subscriberUtils from './subscribers';\n\nimport type { Action, Event, Params, Subscriber } from './types';\nimport type { Database } from '..';\n\nexport type * from './types';\n\nexport type State = Record<string, unknown>;\nexport type States = Map<Subscriber, State>;\n\nexport interface Properties {\n params: Params;\n result?: unknown;\n}\n\nexport interface LifecycleProvider {\n subscribe(subscriber: Subscriber): () => void;\n clear(): void;\n run(action: Action, uid: string, properties: Properties, states?: States): Promise<States>;\n hasSubscribers(action: Action, uid: string): boolean;\n createEvent(action: Action, uid: string, properties: Properties, state: State): Event;\n disable(): void;\n enable(): void;\n}\n\nexport const createLifecyclesProvider = (db: Database): LifecycleProvider => {\n let subscribers = [\n subscriberUtils.timestampsLifecyclesSubscriber,\n subscriberUtils.modelsLifecyclesSubscriber,\n ];\n\n let isLifecycleHooksDisabled = false;\n\n return {\n subscribe(subscriber) {\n assert(\n subscriberUtils.isValidSubscriber(subscriber),\n 'Invalid subscriber. Expected function or object'\n );\n\n subscribers.push(subscriber);\n\n return () => {\n const index = subscribers.indexOf(subscriber);\n\n if (index >= 0) {\n subscribers.splice(index, 1);\n }\n };\n },\n\n clear() {\n subscribers = [];\n },\n\n disable() {\n isLifecycleHooksDisabled = true;\n },\n\n enable() {\n isLifecycleHooksDisabled = false;\n },\n\n /**\n * Whether running `action` on `uid` would reach anyone: a lifecycle declared on the model, a\n * subscriber registered for that model or for every model, or a subscriber function. The\n * provider's own timestamps subscriber does not count: it only stamps the data of a write that\n * is about to happen and observes nothing.\n */\n hasSubscribers(action, uid) {\n if (isLifecycleHooksDisabled) {\n return false;\n }\n\n return subscribers.some((subscriber) => {\n if (subscriber === subscriberUtils.timestampsLifecyclesSubscriber) {\n return false;\n }\n\n if (subscriber === subscriberUtils.modelsLifecyclesSubscriber) {\n const model = db.metadata.get(uid);\n\n return Boolean(model.lifecycles && action in model.lifecycles);\n }\n\n if (typeof subscriber === 'function') {\n return true;\n }\n\n return action in subscriber && (!subscriber.models || subscriber.models.includes(uid));\n });\n },\n\n createEvent(action, uid, properties, state): Event {\n const model = db.metadata.get(uid);\n\n return {\n action,\n model,\n state,\n ...properties,\n };\n },\n\n /**\n * @param {string} action\n * @param {string} uid\n * @param {{ params?: any, result?: any }} properties\n * @param {Map<any, any>} states\n */\n async run(action, uid, properties, states = new Map()) {\n if (isLifecycleHooksDisabled) return states;\n for (let i = 0; i < subscribers.length; i += 1) {\n const subscriber = subscribers[i];\n if (typeof subscriber === 'function') {\n const state = states.get(subscriber) || {};\n const event = this.createEvent(action, uid, properties, state);\n await subscriber(event);\n if (event.state) {\n states.set(subscriber, event.state || state);\n }\n continue;\n }\n\n const hasAction = action in subscriber;\n const hasModel = !subscriber.models || subscriber.models.includes(uid);\n\n if (hasAction && hasModel) {\n const state = states.get(subscriber) || {};\n const event = this.createEvent(action, uid, properties, state);\n\n await subscriber[action]?.(event);\n if (event.state) {\n states.set(subscriber, event.state);\n }\n }\n }\n\n return states;\n },\n };\n};\n"],"names":["createLifecyclesProvider","db","subscribers","subscriberUtils","isLifecycleHooksDisabled","subscribe","subscriber","assert","push","index","indexOf","splice","clear","disable","enable","hasSubscribers","action","uid","some","model","metadata","get","Boolean","lifecycles","models","includes","createEvent","properties","state","run","states","Map","i","length","event","set","hasAction","hasModel"],"mappings":";;;;;AA2BO,MAAMA,2BAA2B,CAACC,EAAAA,GAAAA;AACvC,IAAA,IAAIC,WAAAA,GAAc;AAChBC,QAAAA,8BAA8C;AAC9CA,QAAAA;AACD,KAAA;AAED,IAAA,IAAIC,wBAAAA,GAA2B,KAAA;IAE/B,OAAO;AACLC,QAAAA,SAAAA,CAAAA,CAAUC,UAAU,EAAA;YAClBC,MAAAA,CACEJ,iBAAiC,CAACG,UAAAA,CAAAA,EAClC,iDAAA,CAAA;AAGFJ,YAAAA,WAAAA,CAAYM,IAAI,CAACF,UAAAA,CAAAA;YAEjB,OAAO,IAAA;gBACL,MAAMG,KAAAA,GAAQP,WAAAA,CAAYQ,OAAO,CAACJ,UAAAA,CAAAA;AAElC,gBAAA,IAAIG,SAAS,CAAA,EAAG;oBACdP,WAAAA,CAAYS,MAAM,CAACF,KAAAA,EAAO,CAAA,CAAA;AAC5B,gBAAA;AACF,YAAA,CAAA;AACF,QAAA,CAAA;AAEAG,QAAAA,KAAAA,CAAAA,GAAAA;AACEV,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U,CAACU,MAAAA,CAAO,GAAGkB,KAAAA,CAAAA;oBAC3B,IAAIA,KAAAA,CAAMN,KAAK,EAAE;AACfE,wBAAAA,MAAAA,CAAOK,GAAG,CAAC7B,UAAAA,EAAY4B,KAAAA,CAAMN,KAAK,CAAA;AACpC,oBAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOE,MAAAA;AACT,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -24,7 +24,7 @@ const timestampsLifecyclesSubscriber = {
|
|
|
24
24
|
*/ beforeCreateMany (event) {
|
|
25
25
|
const { data } = event.params;
|
|
26
26
|
const now = new Date();
|
|
27
|
-
if (
|
|
27
|
+
if (Array.isArray(data)) {
|
|
28
28
|
data.forEach((data)=>___default.default.defaults(data, {
|
|
29
29
|
createdAt: now,
|
|
30
30
|
updatedAt: now
|
|
@@ -47,7 +47,7 @@ const timestampsLifecyclesSubscriber = {
|
|
|
47
47
|
*/ beforeUpdateMany (event) {
|
|
48
48
|
const { data } = event.params;
|
|
49
49
|
const now = new Date();
|
|
50
|
-
if (
|
|
50
|
+
if (Array.isArray(data)) {
|
|
51
51
|
data.forEach((data)=>___default.default.assign(data, {
|
|
52
52
|
updatedAt: now
|
|
53
53
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamps.js","sources":["../../../src/lifecycles/subscribers/timestamps.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Event, Subscriber } from '../types';\n\n// NOTE: we could add onCreate & onUpdate on field level to do this instead\nexport const timestampsLifecyclesSubscriber: Subscriber = {\n /**\n * Init createdAt & updatedAt before create\n */\n beforeCreate(event: Event) {\n const { data } = event.params;\n\n const now = new Date();\n _.defaults(data, { createdAt: now, updatedAt: now });\n },\n\n /**\n * Init createdAt & updatedAt before create\n * @param {Event} event\n */\n beforeCreateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (
|
|
1
|
+
{"version":3,"file":"timestamps.js","sources":["../../../src/lifecycles/subscribers/timestamps.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Event, Subscriber } from '../types';\n\n// NOTE: we could add onCreate & onUpdate on field level to do this instead\nexport const timestampsLifecyclesSubscriber: Subscriber = {\n /**\n * Init createdAt & updatedAt before create\n */\n beforeCreate(event: Event) {\n const { data } = event.params;\n\n const now = new Date();\n _.defaults(data, { createdAt: now, updatedAt: now });\n },\n\n /**\n * Init createdAt & updatedAt before create\n * @param {Event} event\n */\n beforeCreateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (Array.isArray(data)) {\n data.forEach((data) => _.defaults(data, { createdAt: now, updatedAt: now }));\n }\n },\n\n /**\n * Update updatedAt before update\n * @param {Event} event\n */\n beforeUpdate(event) {\n const { data } = event.params;\n\n const now = new Date();\n _.assign(data, { updatedAt: now });\n },\n\n /**\n * Update updatedAt before update\n * @param {Event} event\n */\n beforeUpdateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (Array.isArray(data)) {\n data.forEach((data) => _.assign(data, { updatedAt: now }));\n }\n },\n};\n"],"names":["timestampsLifecyclesSubscriber","beforeCreate","event","data","params","now","Date","_","defaults","createdAt","updatedAt","beforeCreateMany","Array","isArray","forEach","beforeUpdate","assign","beforeUpdateMany"],"mappings":";;;;;;;;AAGA;MACaA,8BAAAA,GAA6C;AACxD;;AAEC,MACDC,cAAaC,KAAY,EAAA;AACvB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChBC,kBAAAA,CAAEC,QAAQ,CAACL,IAAAA,EAAM;YAAEM,SAAAA,EAAWJ,GAAAA;YAAKK,SAAAA,EAAWL;AAAI,SAAA,CAAA;AACpD,IAAA,CAAA;AAEA;;;AAGC,MACDM,kBAAiBT,KAAK,EAAA;AACpB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChB,IAAIM,KAAAA,CAAMC,OAAO,CAACV,IAAAA,CAAAA,EAAO;AACvBA,YAAAA,IAAAA,CAAKW,OAAO,CAAC,CAACX,OAASI,kBAAAA,CAAEC,QAAQ,CAACL,IAAAA,EAAM;oBAAEM,SAAAA,EAAWJ,GAAAA;oBAAKK,SAAAA,EAAWL;AAAI,iBAAA,CAAA,CAAA;AAC3E,QAAA;AACF,IAAA,CAAA;AAEA;;;AAGC,MACDU,cAAab,KAAK,EAAA;AAChB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChBC,kBAAAA,CAAES,MAAM,CAACb,IAAAA,EAAM;YAAEO,SAAAA,EAAWL;AAAI,SAAA,CAAA;AAClC,IAAA,CAAA;AAEA;;;AAGC,MACDY,kBAAiBf,KAAK,EAAA;AACpB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChB,IAAIM,KAAAA,CAAMC,OAAO,CAACV,IAAAA,CAAAA,EAAO;AACvBA,YAAAA,IAAAA,CAAKW,OAAO,CAAC,CAACX,OAASI,kBAAAA,CAAES,MAAM,CAACb,IAAAA,EAAM;oBAAEO,SAAAA,EAAWL;AAAI,iBAAA,CAAA,CAAA;AACzD,QAAA;AACF,IAAA;AACF;;;;"}
|
|
@@ -18,7 +18,7 @@ const timestampsLifecyclesSubscriber = {
|
|
|
18
18
|
*/ beforeCreateMany (event) {
|
|
19
19
|
const { data } = event.params;
|
|
20
20
|
const now = new Date();
|
|
21
|
-
if (
|
|
21
|
+
if (Array.isArray(data)) {
|
|
22
22
|
data.forEach((data)=>_.defaults(data, {
|
|
23
23
|
createdAt: now,
|
|
24
24
|
updatedAt: now
|
|
@@ -41,7 +41,7 @@ const timestampsLifecyclesSubscriber = {
|
|
|
41
41
|
*/ beforeUpdateMany (event) {
|
|
42
42
|
const { data } = event.params;
|
|
43
43
|
const now = new Date();
|
|
44
|
-
if (
|
|
44
|
+
if (Array.isArray(data)) {
|
|
45
45
|
data.forEach((data)=>_.assign(data, {
|
|
46
46
|
updatedAt: now
|
|
47
47
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamps.mjs","sources":["../../../src/lifecycles/subscribers/timestamps.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Event, Subscriber } from '../types';\n\n// NOTE: we could add onCreate & onUpdate on field level to do this instead\nexport const timestampsLifecyclesSubscriber: Subscriber = {\n /**\n * Init createdAt & updatedAt before create\n */\n beforeCreate(event: Event) {\n const { data } = event.params;\n\n const now = new Date();\n _.defaults(data, { createdAt: now, updatedAt: now });\n },\n\n /**\n * Init createdAt & updatedAt before create\n * @param {Event} event\n */\n beforeCreateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (
|
|
1
|
+
{"version":3,"file":"timestamps.mjs","sources":["../../../src/lifecycles/subscribers/timestamps.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Event, Subscriber } from '../types';\n\n// NOTE: we could add onCreate & onUpdate on field level to do this instead\nexport const timestampsLifecyclesSubscriber: Subscriber = {\n /**\n * Init createdAt & updatedAt before create\n */\n beforeCreate(event: Event) {\n const { data } = event.params;\n\n const now = new Date();\n _.defaults(data, { createdAt: now, updatedAt: now });\n },\n\n /**\n * Init createdAt & updatedAt before create\n * @param {Event} event\n */\n beforeCreateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (Array.isArray(data)) {\n data.forEach((data) => _.defaults(data, { createdAt: now, updatedAt: now }));\n }\n },\n\n /**\n * Update updatedAt before update\n * @param {Event} event\n */\n beforeUpdate(event) {\n const { data } = event.params;\n\n const now = new Date();\n _.assign(data, { updatedAt: now });\n },\n\n /**\n * Update updatedAt before update\n * @param {Event} event\n */\n beforeUpdateMany(event) {\n const { data } = event.params;\n\n const now = new Date();\n if (Array.isArray(data)) {\n data.forEach((data) => _.assign(data, { updatedAt: now }));\n }\n },\n};\n"],"names":["timestampsLifecyclesSubscriber","beforeCreate","event","data","params","now","Date","_","defaults","createdAt","updatedAt","beforeCreateMany","Array","isArray","forEach","beforeUpdate","assign","beforeUpdateMany"],"mappings":";;AAGA;MACaA,8BAAAA,GAA6C;AACxD;;AAEC,MACDC,cAAaC,KAAY,EAAA;AACvB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChBC,CAAAA,CAAEC,QAAQ,CAACL,IAAAA,EAAM;YAAEM,SAAAA,EAAWJ,GAAAA;YAAKK,SAAAA,EAAWL;AAAI,SAAA,CAAA;AACpD,IAAA,CAAA;AAEA;;;AAGC,MACDM,kBAAiBT,KAAK,EAAA;AACpB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChB,IAAIM,KAAAA,CAAMC,OAAO,CAACV,IAAAA,CAAAA,EAAO;AACvBA,YAAAA,IAAAA,CAAKW,OAAO,CAAC,CAACX,OAASI,CAAAA,CAAEC,QAAQ,CAACL,IAAAA,EAAM;oBAAEM,SAAAA,EAAWJ,GAAAA;oBAAKK,SAAAA,EAAWL;AAAI,iBAAA,CAAA,CAAA;AAC3E,QAAA;AACF,IAAA,CAAA;AAEA;;;AAGC,MACDU,cAAab,KAAK,EAAA;AAChB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChBC,CAAAA,CAAES,MAAM,CAACb,IAAAA,EAAM;YAAEO,SAAAA,EAAWL;AAAI,SAAA,CAAA;AAClC,IAAA,CAAA;AAEA;;;AAGC,MACDY,kBAAiBf,KAAK,EAAA;AACpB,QAAA,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAME,MAAM;AAE7B,QAAA,MAAMC,MAAM,IAAIC,IAAAA,EAAAA;QAChB,IAAIM,KAAAA,CAAMC,OAAO,CAACV,IAAAA,CAAAA,EAAO;AACvBA,YAAAA,IAAAA,CAAKW,OAAO,CAAC,CAACX,OAASI,CAAAA,CAAES,MAAM,CAACb,IAAAA,EAAM;oBAAEO,SAAAA,EAAWL;AAAI,iBAAA,CAAA,CAAA;AACzD,QAAA;AACF,IAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.60.0",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@paralleldrive/cuid2": "2.2.2",
|
|
49
|
-
"@strapi/utils": "5.
|
|
49
|
+
"@strapi/utils": "5.60.0",
|
|
50
50
|
"ajv": "8.20.0",
|
|
51
51
|
"date-fns": "2.30.0",
|
|
52
52
|
"debug": "4.3.4",
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"semver": "7.7.4"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@strapi/typescript-utils": "5.
|
|
59
|
+
"@strapi/typescript-utils": "5.60.0",
|
|
60
60
|
"@types/fs-extra": "11.0.4",
|
|
61
61
|
"@types/jest": "29.5.2",
|
|
62
62
|
"@types/node": "20.19.41",
|
|
63
|
-
"eslint-config-custom": "5.
|
|
63
|
+
"eslint-config-custom": "5.60.0",
|
|
64
64
|
"jest": "29.6.0",
|
|
65
|
-
"tsconfig": "5.
|
|
65
|
+
"tsconfig": "5.60.0",
|
|
66
66
|
"vitest": "catalog:",
|
|
67
|
-
"vitest-config": "5.
|
|
67
|
+
"vitest-config": "5.60.0"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=20.0.0 <=26.x.x",
|