@strapi/database 5.56.0 → 5.58.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/dialects/dialect.d.ts +28 -0
- package/dist/dialects/dialect.d.ts.map +1 -1
- package/dist/dialects/dialect.js +29 -0
- package/dist/dialects/dialect.js.map +1 -1
- package/dist/dialects/dialect.mjs +29 -0
- package/dist/dialects/dialect.mjs.map +1 -1
- package/dist/dialects/mysql/index.d.ts +9 -0
- package/dist/dialects/mysql/index.d.ts.map +1 -1
- package/dist/dialects/mysql/index.js +37 -0
- package/dist/dialects/mysql/index.js.map +1 -1
- package/dist/dialects/mysql/index.mjs +37 -0
- package/dist/dialects/mysql/index.mjs.map +1 -1
- package/dist/dialects/postgresql/index.d.ts +7 -0
- package/dist/dialects/postgresql/index.d.ts.map +1 -1
- package/dist/dialects/postgresql/index.js +50 -0
- package/dist/dialects/postgresql/index.js.map +1 -1
- package/dist/dialects/postgresql/index.mjs +50 -0
- package/dist/dialects/postgresql/index.mjs.map +1 -1
- package/dist/dialects/sqlite/index.d.ts +9 -0
- package/dist/dialects/sqlite/index.d.ts.map +1 -1
- package/dist/dialects/sqlite/index.js +16 -0
- package/dist/dialects/sqlite/index.js.map +1 -1
- package/dist/dialects/sqlite/index.mjs +16 -0
- package/dist/dialects/sqlite/index.mjs.map +1 -1
- package/dist/entity-manager/entity-repository.js +1 -1
- package/dist/entity-manager/entity-repository.js.map +1 -1
- package/dist/entity-manager/entity-repository.mjs +1 -1
- package/dist/entity-manager/entity-repository.mjs.map +1 -1
- package/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/entity-manager/index.js +38 -36
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +38 -36
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/morph-relations.d.ts.map +1 -1
- package/dist/entity-manager/morph-relations.js +3 -5
- package/dist/entity-manager/morph-relations.js.map +1 -1
- package/dist/entity-manager/morph-relations.mjs +3 -5
- package/dist/entity-manager/morph-relations.mjs.map +1 -1
- package/dist/entity-manager/regular-relations.js +3 -3
- package/dist/entity-manager/regular-relations.js.map +1 -1
- package/dist/entity-manager/regular-relations.mjs +3 -3
- package/dist/entity-manager/regular-relations.mjs.map +1 -1
- package/dist/entity-manager/relations-orderer.d.ts.map +1 -1
- package/dist/entity-manager/relations-orderer.js +4 -5
- package/dist/entity-manager/relations-orderer.js.map +1 -1
- package/dist/entity-manager/relations-orderer.mjs +2 -3
- package/dist/entity-manager/relations-orderer.mjs.map +1 -1
- package/dist/fields/biginteger.js +1 -1
- package/dist/fields/biginteger.js.map +1 -1
- package/dist/fields/biginteger.mjs +1 -1
- package/dist/fields/biginteger.mjs.map +1 -1
- package/dist/fields/boolean.js +1 -1
- package/dist/fields/boolean.js.map +1 -1
- package/dist/fields/boolean.mjs +1 -1
- package/dist/fields/boolean.mjs.map +1 -1
- package/dist/fields/number.js +1 -1
- package/dist/fields/number.js.map +1 -1
- package/dist/fields/number.mjs +1 -1
- package/dist/fields/number.mjs.map +1 -1
- package/dist/fields/shared/parsers.js +2 -2
- package/dist/fields/shared/parsers.js.map +1 -1
- package/dist/fields/shared/parsers.mjs +2 -2
- package/dist/fields/shared/parsers.mjs.map +1 -1
- package/dist/fields/string.js +1 -1
- package/dist/fields/string.js.map +1 -1
- package/dist/fields/string.mjs +1 -1
- package/dist/fields/string.mjs.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/metadata/attribute-naming.d.ts +31 -0
- package/dist/metadata/attribute-naming.d.ts.map +1 -0
- package/dist/metadata/attribute-naming.js +39 -0
- package/dist/metadata/attribute-naming.js.map +1 -0
- package/dist/metadata/attribute-naming.mjs +37 -0
- package/dist/metadata/attribute-naming.mjs.map +1 -0
- package/dist/metadata/index.d.ts +5 -2
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/index.js +3 -0
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/index.mjs +3 -1
- package/dist/metadata/index.mjs.map +1 -1
- package/dist/metadata/metadata.d.ts +10 -0
- package/dist/metadata/metadata.d.ts.map +1 -1
- package/dist/metadata/metadata.js +10 -2
- package/dist/metadata/metadata.js.map +1 -1
- package/dist/metadata/metadata.mjs +10 -2
- package/dist/metadata/metadata.mjs.map +1 -1
- package/dist/metadata/relations.d.ts.map +1 -1
- package/dist/metadata/relations.js +6 -5
- package/dist/metadata/relations.js.map +1 -1
- package/dist/metadata/relations.mjs +6 -5
- package/dist/metadata/relations.mjs.map +1 -1
- package/dist/migrations/common.d.ts +2 -0
- package/dist/migrations/common.d.ts.map +1 -1
- package/dist/migrations/common.js.map +1 -1
- package/dist/migrations/common.mjs.map +1 -1
- package/dist/migrations/file-builder.d.ts +97 -0
- package/dist/migrations/file-builder.d.ts.map +1 -0
- package/dist/migrations/file-builder.js +251 -0
- package/dist/migrations/file-builder.js.map +1 -0
- package/dist/migrations/file-builder.mjs +240 -0
- package/dist/migrations/file-builder.mjs.map +1 -0
- package/dist/migrations/index.d.ts +3 -2
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +6 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +6 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs.map +1 -1
- package/dist/migrations/resolver.d.ts.map +1 -1
- package/dist/migrations/resolver.js +4 -1
- package/dist/migrations/resolver.js.map +1 -1
- package/dist/migrations/resolver.mjs +4 -1
- package/dist/migrations/resolver.mjs.map +1 -1
- package/dist/query/helpers/order-by.d.ts.map +1 -1
- package/dist/query/helpers/order-by.js +3 -4
- package/dist/query/helpers/order-by.js.map +1 -1
- package/dist/query/helpers/order-by.mjs +3 -4
- package/dist/query/helpers/order-by.mjs.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.js +46 -30
- package/dist/query/helpers/populate/apply.js.map +1 -1
- package/dist/query/helpers/populate/apply.mjs +46 -30
- package/dist/query/helpers/populate/apply.mjs.map +1 -1
- package/dist/query/helpers/populate/process.js +3 -3
- package/dist/query/helpers/populate/process.js.map +1 -1
- package/dist/query/helpers/populate/process.mjs +3 -3
- package/dist/query/helpers/populate/process.mjs.map +1 -1
- package/dist/query/helpers/search.js +2 -2
- package/dist/query/helpers/search.js.map +1 -1
- package/dist/query/helpers/search.mjs +2 -2
- package/dist/query/helpers/search.mjs.map +1 -1
- package/dist/query/helpers/streams/readable.js +3 -3
- package/dist/query/helpers/streams/readable.js.map +1 -1
- package/dist/query/helpers/streams/readable.mjs +3 -3
- package/dist/query/helpers/streams/readable.mjs.map +1 -1
- package/dist/query/helpers/transform.d.ts.map +1 -1
- package/dist/query/helpers/transform.js +6 -13
- package/dist/query/helpers/transform.js.map +1 -1
- package/dist/query/helpers/transform.mjs +6 -9
- package/dist/query/helpers/transform.mjs.map +1 -1
- package/dist/query/helpers/where.js +13 -9
- package/dist/query/helpers/where.js.map +1 -1
- package/dist/query/helpers/where.mjs +13 -9
- package/dist/query/helpers/where.mjs.map +1 -1
- package/dist/query/query-builder.d.ts.map +1 -1
- package/dist/query/query-builder.js +35 -29
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/query-builder.mjs +35 -29
- package/dist/query/query-builder.mjs.map +1 -1
- package/dist/schema/builder.js +5 -5
- package/dist/schema/builder.js.map +1 -1
- package/dist/schema/builder.mjs +5 -5
- package/dist/schema/builder.mjs.map +1 -1
- package/dist/schema/diff.js +12 -12
- package/dist/schema/diff.js.map +1 -1
- package/dist/schema/diff.mjs +12 -12
- package/dist/schema/diff.mjs.map +1 -1
- package/dist/schema/index.d.ts +3 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/index.mjs +6 -0
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema/rename-helpers.d.ts +78 -0
- package/dist/schema/rename-helpers.d.ts.map +1 -0
- package/dist/schema/rename-helpers.js +235 -0
- package/dist/schema/rename-helpers.js.map +1 -0
- package/dist/schema/rename-helpers.mjs +233 -0
- package/dist/schema/rename-helpers.mjs.map +1 -0
- package/dist/utils/async-curry.d.ts.map +1 -1
- package/dist/utils/async-curry.js +1 -2
- package/dist/utils/async-curry.js.map +1 -1
- package/dist/utils/async-curry.mjs +1 -2
- package/dist/utils/async-curry.mjs.map +1 -1
- package/dist/utils/identifiers/hash.d.ts.map +1 -1
- package/dist/utils/identifiers/hash.js +1 -2
- package/dist/utils/identifiers/hash.js.map +1 -1
- package/dist/utils/identifiers/hash.mjs +1 -2
- package/dist/utils/identifiers/hash.mjs.map +1 -1
- package/dist/utils/identifiers/index.js +8 -10
- package/dist/utils/identifiers/index.js.map +1 -1
- package/dist/utils/identifiers/index.mjs +8 -6
- package/dist/utils/identifiers/index.mjs.map +1 -1
- package/dist/validations/relations/bidirectional.js +1 -1
- package/dist/validations/relations/bidirectional.js.map +1 -1
- package/dist/validations/relations/bidirectional.mjs +1 -1
- package/dist/validations/relations/bidirectional.mjs.map +1 -1
- package/package.json +6 -5
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, type Migration } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport type { Event } 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, JoinTable } from './types';\nimport type { Identifiers } from './utils/identifiers';\nimport { createRepairManager, type RepairManager } from './repairs';\n\nexport { isKnexQuery } from './utils/knex';\nexport { isDatabaseClientKind } from './connection';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: 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}\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 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(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\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 await this.connection.client.acquireConnection();\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 * 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 await this.lifecycles.clear();\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\nexport type { Model, JoinTable, Identifiers, Migration, Event };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","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","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;AA0CA,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;AA0EJ,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,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAAU,CAACG,MAAM,CAACE,iBAAiB,EAAA;AAChD,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACC,QAAQ,CAACC,UAAU,CAACT,MAAAA,CAAAA;AACzB,QAAA,MAAMU,iBAAiB,IAAI,CAAA;AAC3B,QAAA,OAAO,IAAI;AACb,IAAA;AAEAC,IAAAA,KAAAA,CA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3D,IAAI,CAACP,OAAO,CAACgE,SAAS,EAAA;QACxB,CAAA,MAEK;AACH,YAAA,IAAI,CAACxD,MAAM,CAACyD,IAAI,CACd,wJAAA,CAAA;YAGFF,UAAAA,GAAa;AACX,gBAAA,GAAG,IAAI,CAACzD,MAAM,CAACC,UAAU;gBACzBA,UAAAA,EAAY,UAAA;;oBAEV,MAAM2D,IAAAA,GAAO,MAAM,IAAI,CAAC5D,MAAM,CAACC,UAAU,CAACA,UAAU,EAAA;AACpD,oBAAA,IAAI,CAACP,OAAO,CAACgE,SAAS,CAACE,IAAAA,CAAAA;oBACvB,OAAOA,IAAAA;AACT,gBAAA;AACF,aAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACrD,QAAQ,GAAGsD,cAAAA,CAAe,EAAE,CAAA;AAEjC,QAAA,IAAI,CAAC5D,UAAU,GAAG6D,gBAAAA,CAAiBL,UAAAA,EAAY;YAC7CM,IAAAA,EAAM;AAAEzE,gBAAAA,WAAAA,EAAaA,YAAY,IAAI;AAAE;AACzC,SAAA,CAAA;AAEA,QAAA,IAAI,CAAC2C,MAAM,GAAG+B,oBAAAA,CAAqB,IAAI,CAAA;AAEvC,QAAA,IAAI,CAACC,UAAU,GAAGC,wBAAAA,CAAyB,IAAI,CAAA;AAC/C,QAAA,IAAI,CAAChB,UAAU,GAAGiB,wBAAAA,CAAyB,IAAI,CAAA;AAE/C,QAAA,IAAI,CAACrD,aAAa,GAAGsD,mBAAAA,CAAoB,IAAI,CAAA;AAE7C,QAAA,IAAI,CAACC,MAAM,GAAGC,mBAAAA,CAAoB,IAAI,CAAA;AACxC,IAAA;AAkJF;;;;"}
|
|
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';\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';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: 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}\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 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(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\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 await this.connection.client.acquireConnection();\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 * 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 await this.lifecycles.clear();\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","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","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","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;;AAsDA,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;AA0EJ,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,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAA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;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules that turn an attribute's logical name into the physical database
|
|
3
|
+
* identifiers it maps to. This is the only place those rules live: the metadata
|
|
4
|
+
* loader (`metadata.ts`, `relations.ts`) uses them when registering models, and
|
|
5
|
+
* callers that need to predict a name for an attribute that is not registered
|
|
6
|
+
* yet — e.g. the Content-Type Builder computing the *new* side of a rename
|
|
7
|
+
* migration before the server reloads — use them too, so the two can never
|
|
8
|
+
* drift apart.
|
|
9
|
+
*
|
|
10
|
+
* Components, dynamic zones and media do not derive a physical identifier from
|
|
11
|
+
* the attribute name: the name itself is stored as a value in the link table's
|
|
12
|
+
* `field` column (`identifiers.FIELD_COLUMN`).
|
|
13
|
+
*/
|
|
14
|
+
export declare const attributeNaming: {
|
|
15
|
+
/**
|
|
16
|
+
* Column on the model's own table for a scalar attribute.
|
|
17
|
+
*/
|
|
18
|
+
columnName(attributeName: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Column on the model's own table for a relation stored as a join column
|
|
21
|
+
* (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).
|
|
22
|
+
*/
|
|
23
|
+
joinColumnName(attributeName: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Join/link table for a relation owned by `attributeName` on the model whose
|
|
26
|
+
* table is `tableName`.
|
|
27
|
+
*/
|
|
28
|
+
joinTableName(tableName: string, attributeName: string): string;
|
|
29
|
+
};
|
|
30
|
+
export type AttributeNaming = typeof attributeNaming;
|
|
31
|
+
//# sourceMappingURL=attribute-naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-naming.d.ts","sourceRoot":"","sources":["../../src/metadata/attribute-naming.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe;IAC1B;;OAEG;8BACuB,MAAM,GAAG,MAAM;IAIzC;;;OAGG;kCAC2B,MAAM,GAAG,MAAM;IAI7C;;;OAGG;6BACsB,MAAM,iBAAiB,MAAM,GAAG,MAAM;CAGhE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var index = require('../utils/identifiers/index.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The rules that turn an attribute's logical name into the physical database
|
|
8
|
+
* identifiers it maps to. This is the only place those rules live: the metadata
|
|
9
|
+
* loader (`metadata.ts`, `relations.ts`) uses them when registering models, and
|
|
10
|
+
* callers that need to predict a name for an attribute that is not registered
|
|
11
|
+
* yet — e.g. the Content-Type Builder computing the *new* side of a rename
|
|
12
|
+
* migration before the server reloads — use them too, so the two can never
|
|
13
|
+
* drift apart.
|
|
14
|
+
*
|
|
15
|
+
* Components, dynamic zones and media do not derive a physical identifier from
|
|
16
|
+
* the attribute name: the name itself is stored as a value in the link table's
|
|
17
|
+
* `field` column (`identifiers.FIELD_COLUMN`).
|
|
18
|
+
*/ const attributeNaming = {
|
|
19
|
+
/**
|
|
20
|
+
* Column on the model's own table for a scalar attribute.
|
|
21
|
+
*/ columnName (attributeName) {
|
|
22
|
+
return index.identifiers.getColumnName(_.snakeCase(attributeName));
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Column on the model's own table for a relation stored as a join column
|
|
26
|
+
* (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).
|
|
27
|
+
*/ joinColumnName (attributeName) {
|
|
28
|
+
return index.identifiers.getJoinColumnAttributeIdName(_.snakeCase(attributeName));
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Join/link table for a relation owned by `attributeName` on the model whose
|
|
32
|
+
* table is `tableName`.
|
|
33
|
+
*/ joinTableName (tableName, attributeName) {
|
|
34
|
+
return index.identifiers.getJoinTableName(_.snakeCase(tableName), _.snakeCase(attributeName));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.attributeNaming = attributeNaming;
|
|
39
|
+
//# sourceMappingURL=attribute-naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-naming.js","sources":["../../src/metadata/attribute-naming.ts"],"sourcesContent":["import { snakeCase } from 'lodash';\n\nimport { identifiers } from '../utils/identifiers';\n\n/**\n * The rules that turn an attribute's logical name into the physical database\n * identifiers it maps to. This is the only place those rules live: the metadata\n * loader (`metadata.ts`, `relations.ts`) uses them when registering models, and\n * callers that need to predict a name for an attribute that is not registered\n * yet — e.g. the Content-Type Builder computing the *new* side of a rename\n * migration before the server reloads — use them too, so the two can never\n * drift apart.\n *\n * Components, dynamic zones and media do not derive a physical identifier from\n * the attribute name: the name itself is stored as a value in the link table's\n * `field` column (`identifiers.FIELD_COLUMN`).\n */\nexport const attributeNaming = {\n /**\n * Column on the model's own table for a scalar attribute.\n */\n columnName(attributeName: string): string {\n return identifiers.getColumnName(snakeCase(attributeName));\n },\n\n /**\n * Column on the model's own table for a relation stored as a join column\n * (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).\n */\n joinColumnName(attributeName: string): string {\n return identifiers.getJoinColumnAttributeIdName(snakeCase(attributeName));\n },\n\n /**\n * Join/link table for a relation owned by `attributeName` on the model whose\n * table is `tableName`.\n */\n joinTableName(tableName: string, attributeName: string): string {\n return identifiers.getJoinTableName(snakeCase(tableName), snakeCase(attributeName));\n },\n};\n\nexport type AttributeNaming = typeof attributeNaming;\n"],"names":["attributeNaming","columnName","attributeName","identifiers","getColumnName","snakeCase","joinColumnName","getJoinColumnAttributeIdName","joinTableName","tableName","getJoinTableName"],"mappings":";;;;;AAIA;;;;;;;;;;;;UAaaA,eAAAA,GAAkB;AAC7B;;AAEC,MACDC,YAAWC,aAAqB,EAAA;QAC9B,OAAOC,iBAAAA,CAAYC,aAAa,CAACC,WAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC7C,IAAA,CAAA;AAEA;;;AAGC,MACDI,gBAAeJ,aAAqB,EAAA;QAClC,OAAOC,iBAAAA,CAAYI,4BAA4B,CAACF,WAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC5D,IAAA,CAAA;AAEA;;;MAIAM,aAAAA,CAAAA,CAAcC,SAAiB,EAAEP,aAAqB,EAAA;AACpD,QAAA,OAAOC,iBAAAA,CAAYO,gBAAgB,CAACL,WAAAA,CAAUI,YAAYJ,WAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AACtE,IAAA;AACF;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { snakeCase } from 'lodash';
|
|
2
|
+
import { identifiers } from '../utils/identifiers/index.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The rules that turn an attribute's logical name into the physical database
|
|
6
|
+
* identifiers it maps to. This is the only place those rules live: the metadata
|
|
7
|
+
* loader (`metadata.ts`, `relations.ts`) uses them when registering models, and
|
|
8
|
+
* callers that need to predict a name for an attribute that is not registered
|
|
9
|
+
* yet — e.g. the Content-Type Builder computing the *new* side of a rename
|
|
10
|
+
* migration before the server reloads — use them too, so the two can never
|
|
11
|
+
* drift apart.
|
|
12
|
+
*
|
|
13
|
+
* Components, dynamic zones and media do not derive a physical identifier from
|
|
14
|
+
* the attribute name: the name itself is stored as a value in the link table's
|
|
15
|
+
* `field` column (`identifiers.FIELD_COLUMN`).
|
|
16
|
+
*/ const attributeNaming = {
|
|
17
|
+
/**
|
|
18
|
+
* Column on the model's own table for a scalar attribute.
|
|
19
|
+
*/ columnName (attributeName) {
|
|
20
|
+
return identifiers.getColumnName(snakeCase(attributeName));
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Column on the model's own table for a relation stored as a join column
|
|
24
|
+
* (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).
|
|
25
|
+
*/ joinColumnName (attributeName) {
|
|
26
|
+
return identifiers.getJoinColumnAttributeIdName(snakeCase(attributeName));
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Join/link table for a relation owned by `attributeName` on the model whose
|
|
30
|
+
* table is `tableName`.
|
|
31
|
+
*/ joinTableName (tableName, attributeName) {
|
|
32
|
+
return identifiers.getJoinTableName(snakeCase(tableName), snakeCase(attributeName));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { attributeNaming };
|
|
37
|
+
//# sourceMappingURL=attribute-naming.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-naming.mjs","sources":["../../src/metadata/attribute-naming.ts"],"sourcesContent":["import { snakeCase } from 'lodash';\n\nimport { identifiers } from '../utils/identifiers';\n\n/**\n * The rules that turn an attribute's logical name into the physical database\n * identifiers it maps to. This is the only place those rules live: the metadata\n * loader (`metadata.ts`, `relations.ts`) uses them when registering models, and\n * callers that need to predict a name for an attribute that is not registered\n * yet — e.g. the Content-Type Builder computing the *new* side of a rename\n * migration before the server reloads — use them too, so the two can never\n * drift apart.\n *\n * Components, dynamic zones and media do not derive a physical identifier from\n * the attribute name: the name itself is stored as a value in the link table's\n * `field` column (`identifiers.FIELD_COLUMN`).\n */\nexport const attributeNaming = {\n /**\n * Column on the model's own table for a scalar attribute.\n */\n columnName(attributeName: string): string {\n return identifiers.getColumnName(snakeCase(attributeName));\n },\n\n /**\n * Column on the model's own table for a relation stored as a join column\n * (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).\n */\n joinColumnName(attributeName: string): string {\n return identifiers.getJoinColumnAttributeIdName(snakeCase(attributeName));\n },\n\n /**\n * Join/link table for a relation owned by `attributeName` on the model whose\n * table is `tableName`.\n */\n joinTableName(tableName: string, attributeName: string): string {\n return identifiers.getJoinTableName(snakeCase(tableName), snakeCase(attributeName));\n },\n};\n\nexport type AttributeNaming = typeof attributeNaming;\n"],"names":["attributeNaming","columnName","attributeName","identifiers","getColumnName","snakeCase","joinColumnName","getJoinColumnAttributeIdName","joinTableName","tableName","getJoinTableName"],"mappings":";;;AAIA;;;;;;;;;;;;UAaaA,eAAAA,GAAkB;AAC7B;;AAEC,MACDC,YAAWC,aAAqB,EAAA;QAC9B,OAAOC,WAAAA,CAAYC,aAAa,CAACC,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC7C,IAAA,CAAA;AAEA;;;AAGC,MACDI,gBAAeJ,aAAqB,EAAA;QAClC,OAAOC,WAAAA,CAAYI,4BAA4B,CAACF,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC5D,IAAA,CAAA;AAEA;;;MAIAM,aAAAA,CAAAA,CAAcC,SAAiB,EAAEP,aAAqB,EAAA;AACpD,QAAA,OAAOC,WAAAA,CAAYO,gBAAgB,CAACL,SAAAA,CAAUI,YAAYJ,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AACtE,IAAA;AACF;;;;"}
|
package/dist/metadata/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { isPolymorphic, isBidirectional, isAnyToOne, isOneToAny, hasOrderColumn, hasInverseOrderColumn, isManyToAny } from './relations';
|
|
2
|
-
import { Metadata
|
|
2
|
+
import { Metadata } from './metadata';
|
|
3
3
|
import type { Model } from '../types';
|
|
4
|
-
export type {
|
|
4
|
+
export type { Meta } from './metadata';
|
|
5
|
+
export type { AttributeNaming } from './attribute-naming';
|
|
6
|
+
export { attributeNaming } from './attribute-naming';
|
|
7
|
+
export { Metadata };
|
|
5
8
|
export { isPolymorphic, isBidirectional, isAnyToOne, isOneToAny, hasOrderColumn, hasInverseOrderColumn, isManyToAny, };
|
|
6
9
|
/**
|
|
7
10
|
* Create Metadata from models configurations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EACL,aAAa,EACb,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,WAAW,GACZ,CAAC;AAGF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,KAAK,EAAE,KAAG,QAQhD,CAAC"}
|
package/dist/metadata/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var relations = require('./relations.js');
|
|
4
4
|
var metadata = require('./metadata.js');
|
|
5
|
+
require('lodash');
|
|
6
|
+
require('../utils/identifiers/index.js');
|
|
5
7
|
|
|
6
8
|
// TODO: check if there isn't an attribute with an id already
|
|
7
9
|
/**
|
|
@@ -20,5 +22,6 @@ exports.isAnyToOne = relations.isAnyToOne;
|
|
|
20
22
|
exports.isBidirectional = relations.isBidirectional;
|
|
21
23
|
exports.isManyToAny = relations.isManyToAny;
|
|
22
24
|
exports.isOneToAny = relations.isOneToAny;
|
|
25
|
+
exports.Metadata = metadata.Metadata;
|
|
23
26
|
exports.createMetadata = createMetadata;
|
|
24
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/metadata/index.ts"],"sourcesContent":["import {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n} from './relations';\nimport { Metadata
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/metadata/index.ts"],"sourcesContent":["import {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n} from './relations';\nimport { Metadata } from './metadata';\nimport type { Model } from '../types';\n\nexport type { Meta } from './metadata';\nexport type { AttributeNaming } from './attribute-naming';\nexport { attributeNaming } from './attribute-naming';\nexport { Metadata };\nexport {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n};\n\n// TODO: check if there isn't an attribute with an id already\n/**\n * Create Metadata from models configurations\n */\nexport const createMetadata = (models: Model[]): Metadata => {\n const metadata = new Metadata();\n\n if (models.length) {\n metadata.loadModels(models);\n }\n\n return metadata;\n};\n"],"names":["createMetadata","models","metadata","Metadata","length","loadModels"],"mappings":";;;;;;;AA0BA;AACA;;IAGO,MAAMA,cAAAA,GAAiB,CAACC,MAAAA,GAAAA;AAC7B,IAAA,MAAMC,aAAW,IAAIC,iBAAAA,EAAAA;IAErB,IAAIF,MAAAA,CAAOG,MAAM,EAAE;AACjBF,QAAAA,UAAAA,CAASG,UAAU,CAACJ,MAAAA,CAAAA;AACtB,IAAA;IAEA,OAAOC,UAAAA;AACT;;;;;;;;;;;"}
|
package/dist/metadata/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { hasInverseOrderColumn, hasOrderColumn, isAnyToOne, isBidirectional, isManyToAny, isOneToAny } from './relations.mjs';
|
|
2
2
|
import { Metadata } from './metadata.mjs';
|
|
3
|
+
import 'lodash';
|
|
4
|
+
import '../utils/identifiers/index.mjs';
|
|
3
5
|
|
|
4
6
|
// TODO: check if there isn't an attribute with an id already
|
|
5
7
|
/**
|
|
@@ -12,5 +14,5 @@ import { Metadata } from './metadata.mjs';
|
|
|
12
14
|
return metadata;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
export { createMetadata };
|
|
17
|
+
export { Metadata, createMetadata };
|
|
16
18
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/metadata/index.ts"],"sourcesContent":["import {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n} from './relations';\nimport { Metadata
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/metadata/index.ts"],"sourcesContent":["import {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n} from './relations';\nimport { Metadata } from './metadata';\nimport type { Model } from '../types';\n\nexport type { Meta } from './metadata';\nexport type { AttributeNaming } from './attribute-naming';\nexport { attributeNaming } from './attribute-naming';\nexport { Metadata };\nexport {\n isPolymorphic,\n isBidirectional,\n isAnyToOne,\n isOneToAny,\n hasOrderColumn,\n hasInverseOrderColumn,\n isManyToAny,\n};\n\n// TODO: check if there isn't an attribute with an id already\n/**\n * Create Metadata from models configurations\n */\nexport const createMetadata = (models: Model[]): Metadata => {\n const metadata = new Metadata();\n\n if (models.length) {\n metadata.loadModels(models);\n }\n\n return metadata;\n};\n"],"names":["createMetadata","models","metadata","Metadata","length","loadModels"],"mappings":";;;;;AA0BA;AACA;;IAGO,MAAMA,cAAAA,GAAiB,CAACC,MAAAA,GAAAA;AAC7B,IAAA,MAAMC,WAAW,IAAIC,QAAAA,EAAAA;IAErB,IAAIF,MAAAA,CAAOG,MAAM,EAAE;AACjBF,QAAAA,QAAAA,CAASG,UAAU,CAACJ,MAAAA,CAAAA;AACtB,IAAA;IAEA,OAAOC,QAAAA;AACT;;;;"}
|
|
@@ -9,6 +9,16 @@ export interface Meta extends Model {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class Metadata extends Map<string, Meta> {
|
|
11
11
|
get identifiers(): import("..").Identifiers;
|
|
12
|
+
/**
|
|
13
|
+
* The attribute-name -> physical-identifier rules used to build this
|
|
14
|
+
* metadata, for callers that need to predict a name for an attribute that is
|
|
15
|
+
* not registered (see `attribute-naming.ts`).
|
|
16
|
+
*/
|
|
17
|
+
get naming(): {
|
|
18
|
+
columnName(attributeName: string): string;
|
|
19
|
+
joinColumnName(attributeName: string): string;
|
|
20
|
+
joinTableName(tableName: string, attributeName: string): string;
|
|
21
|
+
};
|
|
12
22
|
get(key: string): Meta;
|
|
13
23
|
add(meta: Meta): this;
|
|
14
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/metadata/metadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/metadata/metadata.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAa,KAAK,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,WAAW,IAAK,SAAQ,KAAK;IACjC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,OAAO,EAAE,KAAK,EAAE,CAAC;IACjB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CACnD;AAED,qBAAa,QAAS,SAAQ,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;IAI7C,IAAI,WAAW,6BAEd;IAED;;;;OAIG;IACH,IAAI,MAAM;;;;MAET;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQtB,GAAG,CAAC,IAAI,EAAE,IAAI;IAId;;OAEG;IACH,QAAQ;IAYR,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE;CAwD3B"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _ = require('lodash
|
|
3
|
+
var _ = require('lodash');
|
|
4
4
|
var index = require('../utils/identifiers/index.js');
|
|
5
5
|
var types = require('../utils/types.js');
|
|
6
6
|
var relations = require('./relations.js');
|
|
7
|
+
var attributeNaming = require('./attribute-naming.js');
|
|
7
8
|
|
|
8
9
|
class Metadata extends Map {
|
|
9
10
|
// TODO: we expose the global identifiers in this way so that in the future we can instantiate our own
|
|
@@ -12,6 +13,13 @@ class Metadata extends Map {
|
|
|
12
13
|
get identifiers() {
|
|
13
14
|
return index.identifiers;
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* The attribute-name -> physical-identifier rules used to build this
|
|
18
|
+
* metadata, for callers that need to predict a name for an attribute that is
|
|
19
|
+
* not registered (see `attribute-naming.ts`).
|
|
20
|
+
*/ get naming() {
|
|
21
|
+
return attributeNaming.attributeNaming;
|
|
22
|
+
}
|
|
15
23
|
get(key) {
|
|
16
24
|
if (!super.has(key)) {
|
|
17
25
|
throw new Error(`Metadata for "${key}" not found`);
|
|
@@ -90,7 +98,7 @@ const createAttribute = (attributeName, attribute)=>{
|
|
|
90
98
|
if ('columnName' in attribute && attribute.columnName) {
|
|
91
99
|
return;
|
|
92
100
|
}
|
|
93
|
-
const columnName =
|
|
101
|
+
const columnName = attributeNaming.attributeNaming.columnName(attributeName);
|
|
94
102
|
Object.assign(attribute, {
|
|
95
103
|
columnName
|
|
96
104
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sources":["../../src/metadata/metadata.ts"],"sourcesContent":["import { cloneDeep
|
|
1
|
+
{"version":3,"file":"metadata.js","sources":["../../src/metadata/metadata.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport { identifiers } from '../utils/identifiers';\nimport * as types from '../utils/types';\nimport { createRelation } from './relations';\nimport { attributeNaming } from './attribute-naming';\nimport type { Attribute, Model } from '../types';\nimport type { ForeignKey, Index } from '../schema/types';\nimport type { Action, SubscriberFn } from '../lifecycles';\n\nexport interface Meta extends Model {\n columnToAttribute: Record<string, string>;\n indexes: Index[];\n foreignKeys: ForeignKey[];\n lifecycles: Partial<Record<Action, SubscriberFn>>;\n}\n\nexport class Metadata extends Map<string, Meta> {\n // TODO: we expose the global identifiers in this way so that in the future we can instantiate our own\n // However, it should NOT be done until all the methods used by metadata can be part of this metadata object\n // and access this one; currently they all access the global identifiers directly.\n get identifiers() {\n return identifiers;\n }\n\n /**\n * The attribute-name -> physical-identifier rules used to build this\n * metadata, for callers that need to predict a name for an attribute that is\n * not registered (see `attribute-naming.ts`).\n */\n get naming() {\n return attributeNaming;\n }\n\n get(key: string): Meta {\n if (!super.has(key)) {\n throw new Error(`Metadata for \"${key}\" not found`);\n }\n\n return super.get(key) as Meta;\n }\n\n add(meta: Meta) {\n return this.set(meta.uid, meta);\n }\n\n /**\n * Validate the DB metadata, throwing an error if a duplicate DB table name is detected\n */\n validate() {\n const seenTables = new Map();\n for (const meta of this.values()) {\n if (seenTables.get(meta.tableName)) {\n throw new Error(\n `DB table \"${meta.tableName}\" already exists. Change the collectionName of the related content type.`\n );\n }\n seenTables.set(meta.tableName, true);\n }\n }\n\n loadModels(models: Model[]) {\n // init pass\n for (const model of cloneDeep(models ?? [])) {\n const tableName = identifiers.getTableName(model.tableName);\n this.add({\n ...model,\n tableName,\n attributes: {\n ...model.attributes,\n },\n lifecycles: model.lifecycles ?? {},\n indexes: model.indexes ?? [],\n foreignKeys: model.foreignKeys ?? [],\n columnToAttribute: {},\n });\n }\n\n // build compos / relations\n for (const meta of this.values()) {\n for (const [attributeName, attribute] of Object.entries(meta.attributes)) {\n try {\n if (attribute.unstable_virtual) {\n continue;\n }\n\n if (types.isRelationalAttribute(attribute)) {\n createRelation(attributeName, attribute, meta, this);\n continue;\n }\n\n createAttribute(attributeName, attribute);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Error on attribute ${attributeName} in model ${meta.singularName}(${meta.uid}): ${error.message}`\n );\n }\n }\n }\n }\n\n for (const meta of this.values()) {\n const columnToAttribute = Object.keys(meta.attributes).reduce((acc, key) => {\n const attribute = meta.attributes[key];\n if ('columnName' in attribute) {\n return Object.assign(acc, { [attribute.columnName || key]: key });\n }\n\n return Object.assign(acc, { [key]: key });\n }, {});\n\n meta.columnToAttribute = columnToAttribute;\n }\n\n this.validate();\n }\n}\n\nconst createAttribute = (attributeName: string, attribute: Attribute) => {\n // if the attribute has already set its own column name, use that\n // this will prevent us from shortening a name twice\n if ('columnName' in attribute && attribute.columnName) {\n return;\n }\n\n const columnName = attributeNaming.columnName(attributeName);\n\n Object.assign(attribute, { columnName });\n};\n"],"names":["Metadata","Map","identifiers","naming","attributeNaming","get","key","has","Error","add","meta","set","uid","validate","seenTables","values","tableName","loadModels","models","model","cloneDeep","getTableName","attributes","lifecycles","indexes","foreignKeys","columnToAttribute","attributeName","attribute","Object","entries","unstable_virtual","types","createRelation","createAttribute","error","singularName","message","keys","reduce","acc","assign","columnName"],"mappings":";;;;;;;;AAgBO,MAAMA,QAAAA,SAAiBC,GAAAA,CAAAA;;;;AAI5B,IAAA,IAAIC,WAAAA,GAAc;QAChB,OAAOA,iBAAAA;AACT,IAAA;AAEA;;;;AAIC,MACD,IAAIC,MAAAA,GAAS;QACX,OAAOC,+BAAAA;AACT,IAAA;AAEAC,IAAAA,GAAAA,CAAIC,GAAW,EAAQ;AACrB,QAAA,IAAI,CAAC,KAAK,CAACC,GAAAA,CAAID,GAAAA,CAAAA,EAAM;AACnB,YAAA,MAAM,IAAIE,KAAAA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GAAAA,EAAK;AAAE,wBAAA,CAACZ,SAAAA,CAAUc,UAAU,IAAIpC,GAAAA,GAAMA;AAAI,qBAAA,CAAA;AACjE,gBAAA;gBAEA,OAAOuB,MAAAA,CAAOY,MAAM,CAACD,GAAAA,EAAK;AAAE,oBAAA,CAAClC,MAAMA;AAAI,iBAAA,CAAA;AACzC,YAAA,CAAA,EAAG,EAAC,CAAA;AAEJI,YAAAA,IAAAA,CAAKgB,iBAAiB,GAAGA,iBAAAA;AAC3B,QAAA;AAEA,QAAA,IAAI,CAACb,QAAQ,EAAA;AACf,IAAA;AACF;AAEA,MAAMqB,eAAAA,GAAkB,CAACP,aAAAA,EAAuBC,SAAAA,GAAAA;;;AAG9C,IAAA,IAAI,YAAA,IAAgBA,SAAAA,IAAaA,SAAAA,CAAUc,UAAU,EAAE;AACrD,QAAA;AACF,IAAA;IAEA,MAAMA,UAAAA,GAAatC,+BAAAA,CAAgBsC,UAAU,CAACf,aAAAA,CAAAA;IAE9CE,MAAAA,CAAOY,MAAM,CAACb,SAAAA,EAAW;AAAEc,QAAAA;AAAW,KAAA,CAAA;AACxC,CAAA;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { cloneDeep
|
|
1
|
+
import { cloneDeep } from 'lodash';
|
|
2
2
|
import { identifiers } from '../utils/identifiers/index.mjs';
|
|
3
3
|
import { isRelationalAttribute } from '../utils/types.mjs';
|
|
4
4
|
import { createRelation } from './relations.mjs';
|
|
5
|
+
import { attributeNaming } from './attribute-naming.mjs';
|
|
5
6
|
|
|
6
7
|
class Metadata extends Map {
|
|
7
8
|
// TODO: we expose the global identifiers in this way so that in the future we can instantiate our own
|
|
@@ -10,6 +11,13 @@ class Metadata extends Map {
|
|
|
10
11
|
get identifiers() {
|
|
11
12
|
return identifiers;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The attribute-name -> physical-identifier rules used to build this
|
|
16
|
+
* metadata, for callers that need to predict a name for an attribute that is
|
|
17
|
+
* not registered (see `attribute-naming.ts`).
|
|
18
|
+
*/ get naming() {
|
|
19
|
+
return attributeNaming;
|
|
20
|
+
}
|
|
13
21
|
get(key) {
|
|
14
22
|
if (!super.has(key)) {
|
|
15
23
|
throw new Error(`Metadata for "${key}" not found`);
|
|
@@ -88,7 +96,7 @@ const createAttribute = (attributeName, attribute)=>{
|
|
|
88
96
|
if ('columnName' in attribute && attribute.columnName) {
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
91
|
-
const columnName =
|
|
99
|
+
const columnName = attributeNaming.columnName(attributeName);
|
|
92
100
|
Object.assign(attribute, {
|
|
93
101
|
columnName
|
|
94
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","sources":["../../src/metadata/metadata.ts"],"sourcesContent":["import { cloneDeep
|
|
1
|
+
{"version":3,"file":"metadata.mjs","sources":["../../src/metadata/metadata.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport { identifiers } from '../utils/identifiers';\nimport * as types from '../utils/types';\nimport { createRelation } from './relations';\nimport { attributeNaming } from './attribute-naming';\nimport type { Attribute, Model } from '../types';\nimport type { ForeignKey, Index } from '../schema/types';\nimport type { Action, SubscriberFn } from '../lifecycles';\n\nexport interface Meta extends Model {\n columnToAttribute: Record<string, string>;\n indexes: Index[];\n foreignKeys: ForeignKey[];\n lifecycles: Partial<Record<Action, SubscriberFn>>;\n}\n\nexport class Metadata extends Map<string, Meta> {\n // TODO: we expose the global identifiers in this way so that in the future we can instantiate our own\n // However, it should NOT be done until all the methods used by metadata can be part of this metadata object\n // and access this one; currently they all access the global identifiers directly.\n get identifiers() {\n return identifiers;\n }\n\n /**\n * The attribute-name -> physical-identifier rules used to build this\n * metadata, for callers that need to predict a name for an attribute that is\n * not registered (see `attribute-naming.ts`).\n */\n get naming() {\n return attributeNaming;\n }\n\n get(key: string): Meta {\n if (!super.has(key)) {\n throw new Error(`Metadata for \"${key}\" not found`);\n }\n\n return super.get(key) as Meta;\n }\n\n add(meta: Meta) {\n return this.set(meta.uid, meta);\n }\n\n /**\n * Validate the DB metadata, throwing an error if a duplicate DB table name is detected\n */\n validate() {\n const seenTables = new Map();\n for (const meta of this.values()) {\n if (seenTables.get(meta.tableName)) {\n throw new Error(\n `DB table \"${meta.tableName}\" already exists. Change the collectionName of the related content type.`\n );\n }\n seenTables.set(meta.tableName, true);\n }\n }\n\n loadModels(models: Model[]) {\n // init pass\n for (const model of cloneDeep(models ?? [])) {\n const tableName = identifiers.getTableName(model.tableName);\n this.add({\n ...model,\n tableName,\n attributes: {\n ...model.attributes,\n },\n lifecycles: model.lifecycles ?? {},\n indexes: model.indexes ?? [],\n foreignKeys: model.foreignKeys ?? [],\n columnToAttribute: {},\n });\n }\n\n // build compos / relations\n for (const meta of this.values()) {\n for (const [attributeName, attribute] of Object.entries(meta.attributes)) {\n try {\n if (attribute.unstable_virtual) {\n continue;\n }\n\n if (types.isRelationalAttribute(attribute)) {\n createRelation(attributeName, attribute, meta, this);\n continue;\n }\n\n createAttribute(attributeName, attribute);\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(\n `Error on attribute ${attributeName} in model ${meta.singularName}(${meta.uid}): ${error.message}`\n );\n }\n }\n }\n }\n\n for (const meta of this.values()) {\n const columnToAttribute = Object.keys(meta.attributes).reduce((acc, key) => {\n const attribute = meta.attributes[key];\n if ('columnName' in attribute) {\n return Object.assign(acc, { [attribute.columnName || key]: key });\n }\n\n return Object.assign(acc, { [key]: key });\n }, {});\n\n meta.columnToAttribute = columnToAttribute;\n }\n\n this.validate();\n }\n}\n\nconst createAttribute = (attributeName: string, attribute: Attribute) => {\n // if the attribute has already set its own column name, use that\n // this will prevent us from shortening a name twice\n if ('columnName' in attribute && attribute.columnName) {\n return;\n }\n\n const columnName = attributeNaming.columnName(attributeName);\n\n Object.assign(attribute, { columnName });\n};\n"],"names":["Metadata","Map","identifiers","naming","attributeNaming","get","key","has","Error","add","meta","set","uid","validate","seenTables","values","tableName","loadModels","models","model","cloneDeep","getTableName","attributes","lifecycles","indexes","foreignKeys","columnToAttribute","attributeName","attribute","Object","entries","unstable_virtual","types","createRelation","createAttribute","error","singularName","message","keys","reduce","acc","assign","columnName"],"mappings":";;;;;;AAgBO,MAAMA,QAAAA,SAAiBC,GAAAA,CAAAA;;;;AAI5B,IAAA,IAAIC,WAAAA,GAAc;QAChB,OAAOA,WAAAA;AACT,IAAA;AAEA;;;;AAIC,MACD,IAAIC,MAAAA,GAAS;QACX,OAAOC,eAAAA;AACT,IAAA;AAEAC,IAAAA,GAAAA,CAAIC,GAAW,EAAQ;AACrB,QAAA,IAAI,CAAC,KAAK,CAACC,GAAAA,CAAID,GAAAA,CAAAA,EAAM;AACnB,YAAA,MAAM,IAAIE,KAAAA,CAAM,CAAC,cAAc,EAAEF,GAAAA,CAAI,WAAW,CAAC,CAAA;AACnD,QAAA;QAEA,OAAO,KAAK,CAACD,GAAAA,CAAIC,GAAAA,CAAAA;AACnB,IAAA;AAEAG,IAAAA,GAAAA,CAAIC,IAAU,EAAE;AACd,QAAA,OAAO,IAAI,CAACC,GAAG,CAACD,IAAAA,CAAKE,GAAG,EAAEF,IAAAA,CAAAA;AAC5B,IAAA;AAEA;;AAEC,MACDG,QAAAA,GAAW;AACT,QAAA,MAAMC,aAAa,IAAIb,GAAAA,EAAAA;AACvB,QAAA,KAAK,MAAMS,IAAAA,IAAQ,IAAI,CAACK,MAAM,EAAA,CAAI;AAChC,YAAA,IAAID,UAAAA,CAAWT,GAAG,CAACK,IAAAA,CAAKM,SAAS,CAAA,EAAG;gBAClC,MAAM,IAAIR,MACR,CAAC,UAAU,EAAEE,IAAAA,CAAKM,SAAS,CAAC,wEAAwE,CAAC,CAAA;AAEzG,YAAA;AACAF,YAAAA,UAAAA,CAAWH,GAAG,CAACD,IAAAA,CAAKM,SAAS,EAAE,IAAA,CAAA;AACjC,QAAA;AACF,IAAA;AAEAC,IAAAA,UAAAA,CAAWC,MAAe,EAAE;;AAE1B,QAAA,KAAK,MAAMC,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["../../src/metadata/relations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../src/metadata/relations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAkB,MAAM,UAAU,CAAC;AA0B9E,eAAO,MAAM,aAAa,GAAI,WAAW,mBAAmB,KAAG,SAAS,IAAI,QAAQ,CAAC,KACA,CAAC;AAEtF,eAAO,MAAM,UAAU,GACrB,WAAW,mBAAmB,KAC7B,SAAS,IAAI,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,SACW,CAAC;AAEzD,eAAO,MAAM,WAAW,GACtB,WAAW,mBAAmB,KAC7B,SAAS,IAAI,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,UACY,CAAC;AAE3D,eAAO,MAAM,UAAU,GACrB,WAAW,mBAAmB,KAC7B,SAAS,IAAI,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,SACW,CAAC;AAEzD,eAAO,MAAM,WAAW,GACtB,WAAW,mBAAmB,KAC7B,SAAS,IAAI,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,UACY,CAAC;AAE3D,eAAO,MAAM,eAAe,GAC1B,WAAW,mBAAmB,KAC7B,SAAS,IAAI,QAAQ,CAAC,aAAmE,CAAC;AAU7F,eAAO,MAAM,cAAc,GAAI,WAAW,mBAAmB,0DAA2B,CAAC;AACzF,eAAO,MAAM,qBAAqB,GAAI,WAAW,mBAAmB,0DACd,CAAC;AAoiBvD;;GAEG;AACH,eAAO,MAAM,cAAc,GACzB,eAAe,MAAM,EACrB,WAAW,mBAAmB,EAC9B,MAAM,IAAI,EACV,UAAU,QAAQ,SAuBnB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _ = require('lodash
|
|
3
|
+
var _ = require('lodash');
|
|
4
4
|
var index = require('../utils/identifiers/index.js');
|
|
5
|
+
var attributeNaming = require('./attribute-naming.js');
|
|
5
6
|
|
|
6
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
|
|
@@ -273,7 +274,7 @@ const hasInverseOrderColumn = (attribute)=>isBidirectional(attribute) && isManyT
|
|
|
273
274
|
if (!targetMeta) {
|
|
274
275
|
throw new Error(`Morph target not found. Looking for ${attribute.target}`);
|
|
275
276
|
}
|
|
276
|
-
if (attribute.morphBy && !___default.default.has(
|
|
277
|
+
if (attribute.morphBy && !___default.default.has(targetMeta.attributes, attribute.morphBy)) {
|
|
277
278
|
throw new Error(`Morph target attribute not found. Looking for ${attribute.morphBy}`);
|
|
278
279
|
}
|
|
279
280
|
};
|
|
@@ -284,7 +285,7 @@ const hasInverseOrderColumn = (attribute)=>isBidirectional(attribute) && isManyT
|
|
|
284
285
|
if (!targetMeta) {
|
|
285
286
|
throw new Error(`Morph target not found. Looking for ${attribute.target}`);
|
|
286
287
|
}
|
|
287
|
-
if (attribute.morphBy && !___default.default.has(
|
|
288
|
+
if (attribute.morphBy && !___default.default.has(targetMeta.attributes, attribute.morphBy)) {
|
|
288
289
|
throw new Error(`Morph target attribute not found. Looking for ${attribute.morphBy}`);
|
|
289
290
|
}
|
|
290
291
|
};
|
|
@@ -295,7 +296,7 @@ const hasInverseOrderColumn = (attribute)=>isBidirectional(attribute) && isManyT
|
|
|
295
296
|
if (!targetMeta) {
|
|
296
297
|
throw new Error(`Unknown target ${attribute.target}`);
|
|
297
298
|
}
|
|
298
|
-
const joinColumnName =
|
|
299
|
+
const joinColumnName = attributeNaming.attributeNaming.joinColumnName(attributeName);
|
|
299
300
|
const joinColumn = {
|
|
300
301
|
name: joinColumnName,
|
|
301
302
|
referencedColumn: ID,
|
|
@@ -332,7 +333,7 @@ const hasInverseOrderColumn = (attribute)=>isBidirectional(attribute) && isManyT
|
|
|
332
333
|
if ('joinTable' in attribute && attribute.joinTable && !attribute.joinTable.__internal__) {
|
|
333
334
|
return;
|
|
334
335
|
}
|
|
335
|
-
const joinTableName =
|
|
336
|
+
const joinTableName = attributeNaming.attributeNaming.joinTableName(meta.tableName, attributeName);
|
|
336
337
|
const joinColumnName = index.identifiers.getJoinColumnAttributeIdName(_.snakeCase(meta.singularName));
|
|
337
338
|
let inverseJoinColumnName = index.identifiers.getJoinColumnAttributeIdName(_.snakeCase(targetMeta.singularName));
|
|
338
339
|
// if relation is self referencing
|