drizzle-orm 0.43.1 → 0.44.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/aws-data-api/pg/driver.cjs +5 -1
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +1 -0
- package/aws-data-api/pg/driver.d.ts +1 -0
- package/aws-data-api/pg/driver.js +5 -1
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/session.cjs +15 -4
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +13 -2
- package/aws-data-api/pg/session.d.ts +13 -2
- package/aws-data-api/pg/session.js +15 -4
- package/aws-data-api/pg/session.js.map +1 -1
- package/better-sqlite3/driver.cjs +1 -2
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.js +1 -2
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/session.cjs +9 -3
- package/better-sqlite3/session.cjs.map +1 -1
- package/better-sqlite3/session.d.cts +12 -2
- package/better-sqlite3/session.d.ts +12 -2
- package/better-sqlite3/session.js +9 -3
- package/better-sqlite3/session.js.map +1 -1
- package/bun-sql/driver.cjs +6 -3
- package/bun-sql/driver.cjs.map +1 -1
- package/bun-sql/driver.js +6 -3
- package/bun-sql/driver.js.map +1 -1
- package/bun-sql/session.cjs +21 -9
- package/bun-sql/session.cjs.map +1 -1
- package/bun-sql/session.d.cts +12 -2
- package/bun-sql/session.d.ts +12 -2
- package/bun-sql/session.js +21 -9
- package/bun-sql/session.js.map +1 -1
- package/bun-sqlite/driver.cjs +1 -2
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.js +1 -2
- package/bun-sqlite/driver.js.map +1 -1
- package/cache/core/cache.cjs +58 -0
- package/cache/core/cache.cjs.map +1 -0
- package/cache/core/cache.d.cts +36 -0
- package/cache/core/cache.d.ts +36 -0
- package/cache/core/cache.js +32 -0
- package/cache/core/cache.js.map +1 -0
- package/cache/core/index.cjs +23 -0
- package/cache/core/index.cjs.map +1 -0
- package/cache/core/index.d.cts +1 -0
- package/cache/core/index.d.ts +1 -0
- package/cache/core/index.js +2 -0
- package/cache/core/index.js.map +1 -0
- package/cache/core/types.cjs +17 -0
- package/cache/core/types.cjs.map +1 -0
- package/cache/core/types.d.cts +33 -0
- package/cache/core/types.d.ts +33 -0
- package/cache/core/types.js +1 -0
- package/cache/core/types.js.map +1 -0
- package/cache/upstash/cache.cjs +195 -0
- package/cache/upstash/cache.cjs.map +1 -0
- package/cache/upstash/cache.d.cts +59 -0
- package/cache/upstash/cache.d.ts +59 -0
- package/cache/upstash/cache.js +170 -0
- package/cache/upstash/cache.js.map +1 -0
- package/cache/upstash/index.cjs +23 -0
- package/cache/upstash/index.cjs.map +1 -0
- package/cache/upstash/index.d.cts +1 -0
- package/cache/upstash/index.d.ts +1 -0
- package/cache/upstash/index.js +2 -0
- package/cache/upstash/index.js.map +1 -0
- package/casing.cjs +1 -2
- package/casing.cjs.map +1 -1
- package/casing.js +1 -2
- package/casing.js.map +1 -1
- package/column-builder.cjs +1 -2
- package/column-builder.cjs.map +1 -1
- package/column-builder.js +1 -2
- package/column-builder.js.map +1 -1
- package/d1/driver.cjs +5 -1
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.js +5 -1
- package/d1/driver.js.map +1 -1
- package/d1/session.cjs +23 -9
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +12 -2
- package/d1/session.d.ts +12 -2
- package/d1/session.js +23 -9
- package/d1/session.js.map +1 -1
- package/durable-sqlite/session.cjs +1 -1
- package/durable-sqlite/session.cjs.map +1 -1
- package/durable-sqlite/session.js +1 -1
- package/durable-sqlite/session.js.map +1 -1
- package/errors/index.cjs +39 -0
- package/errors/index.cjs.map +1 -0
- package/errors/index.d.cts +6 -0
- package/errors/index.d.ts +6 -0
- package/errors/index.js +15 -0
- package/errors/index.js.map +1 -0
- package/gel/driver.cjs +10 -4
- package/gel/driver.cjs.map +1 -1
- package/gel/driver.d.cts +2 -0
- package/gel/driver.d.ts +2 -0
- package/gel/driver.js +10 -4
- package/gel/driver.js.map +1 -1
- package/gel/session.cjs +25 -10
- package/gel/session.cjs.map +1 -1
- package/gel/session.d.cts +12 -2
- package/gel/session.d.ts +12 -2
- package/gel/session.js +25 -10
- package/gel/session.js.map +1 -1
- package/gel-core/db.cjs +3 -0
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.cts +4 -0
- package/gel-core/db.d.ts +4 -0
- package/gel-core/db.js +3 -0
- package/gel-core/db.js.map +1 -1
- package/gel-core/dialect.cjs +1 -2
- package/gel-core/dialect.cjs.map +1 -1
- package/gel-core/dialect.js +1 -2
- package/gel-core/dialect.js.map +1 -1
- package/gel-core/query-builders/delete.cjs +5 -1
- package/gel-core/query-builders/delete.cjs.map +1 -1
- package/gel-core/query-builders/delete.js +5 -1
- package/gel-core/query-builders/delete.js.map +1 -1
- package/gel-core/query-builders/insert.cjs +5 -1
- package/gel-core/query-builders/insert.cjs.map +1 -1
- package/gel-core/query-builders/insert.js +5 -1
- package/gel-core/query-builders/insert.js.map +1 -1
- package/gel-core/query-builders/select.cjs +26 -4
- package/gel-core/query-builders/select.cjs.map +1 -1
- package/gel-core/query-builders/select.d.cts +9 -0
- package/gel-core/query-builders/select.d.ts +9 -0
- package/gel-core/query-builders/select.js +26 -4
- package/gel-core/query-builders/select.js.map +1 -1
- package/gel-core/query-builders/update.cjs +5 -1
- package/gel-core/query-builders/update.cjs.map +1 -1
- package/gel-core/query-builders/update.js +5 -1
- package/gel-core/query-builders/update.js.map +1 -1
- package/gel-core/session.cjs +78 -1
- package/gel-core/session.cjs.map +1 -1
- package/gel-core/session.d.cts +13 -2
- package/gel-core/session.d.ts +13 -2
- package/gel-core/session.js +79 -2
- package/gel-core/session.js.map +1 -1
- package/gel-core/utils.cjs +16 -0
- package/gel-core/utils.cjs.map +1 -1
- package/gel-core/utils.d.cts +8 -4
- package/gel-core/utils.d.ts +8 -4
- package/gel-core/utils.js +15 -0
- package/gel-core/utils.js.map +1 -1
- package/index.cjs +16 -16
- package/index.cjs.map +1 -1
- package/libsql/driver-core.cjs +5 -1
- package/libsql/driver-core.cjs.map +1 -1
- package/libsql/driver-core.js +5 -1
- package/libsql/driver-core.js.map +1 -1
- package/libsql/driver.cjs +1 -2
- package/libsql/driver.cjs.map +1 -1
- package/libsql/driver.js +1 -2
- package/libsql/driver.js.map +1 -1
- package/libsql/http/index.cjs +1 -2
- package/libsql/http/index.cjs.map +1 -1
- package/libsql/http/index.js +1 -2
- package/libsql/http/index.js.map +1 -1
- package/libsql/node/index.cjs +1 -2
- package/libsql/node/index.cjs.map +1 -1
- package/libsql/node/index.js +1 -2
- package/libsql/node/index.js.map +1 -1
- package/libsql/session.cjs +27 -13
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +12 -2
- package/libsql/session.d.ts +12 -2
- package/libsql/session.js +27 -13
- package/libsql/session.js.map +1 -1
- package/libsql/sqlite3/index.cjs +1 -2
- package/libsql/sqlite3/index.cjs.map +1 -1
- package/libsql/sqlite3/index.js +1 -2
- package/libsql/sqlite3/index.js.map +1 -1
- package/libsql/wasm/index.cjs +1 -2
- package/libsql/wasm/index.cjs.map +1 -1
- package/libsql/wasm/index.js +1 -2
- package/libsql/wasm/index.js.map +1 -1
- package/libsql/web/index.cjs +1 -2
- package/libsql/web/index.cjs.map +1 -1
- package/libsql/web/index.js +1 -2
- package/libsql/web/index.js.map +1 -1
- package/libsql/ws/index.cjs +1 -2
- package/libsql/ws/index.cjs.map +1 -1
- package/libsql/ws/index.js +1 -2
- package/libsql/ws/index.js.map +1 -1
- package/mysql-core/columns/binary.cjs +2 -4
- package/mysql-core/columns/binary.cjs.map +1 -1
- package/mysql-core/columns/binary.js +2 -4
- package/mysql-core/columns/binary.js.map +1 -1
- package/mysql-core/columns/decimal.cjs +2 -4
- package/mysql-core/columns/decimal.cjs.map +1 -1
- package/mysql-core/columns/decimal.js +2 -4
- package/mysql-core/columns/decimal.js.map +1 -1
- package/mysql-core/columns/varbinary.cjs +2 -4
- package/mysql-core/columns/varbinary.cjs.map +1 -1
- package/mysql-core/columns/varbinary.js +2 -4
- package/mysql-core/columns/varbinary.js.map +1 -1
- package/mysql-core/db.cjs +3 -0
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +4 -0
- package/mysql-core/db.d.ts +4 -0
- package/mysql-core/db.js +3 -0
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/dialect.cjs +1 -2
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +1 -2
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/delete.cjs +9 -1
- package/mysql-core/query-builders/delete.cjs.map +1 -1
- package/mysql-core/query-builders/delete.js +9 -1
- package/mysql-core/query-builders/delete.js.map +1 -1
- package/mysql-core/query-builders/insert.cjs +8 -1
- package/mysql-core/query-builders/insert.cjs.map +1 -1
- package/mysql-core/query-builders/insert.d.cts +2 -0
- package/mysql-core/query-builders/insert.d.ts +2 -0
- package/mysql-core/query-builders/insert.js +8 -1
- package/mysql-core/query-builders/insert.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +24 -3
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.d.cts +9 -0
- package/mysql-core/query-builders/select.d.ts +9 -0
- package/mysql-core/query-builders/select.js +25 -4
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/query-builders/update.cjs +11 -1
- package/mysql-core/query-builders/update.cjs.map +1 -1
- package/mysql-core/query-builders/update.d.cts +2 -0
- package/mysql-core/query-builders/update.d.ts +2 -0
- package/mysql-core/query-builders/update.js +11 -1
- package/mysql-core/query-builders/update.js.map +1 -1
- package/mysql-core/session.cjs +79 -0
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +14 -1
- package/mysql-core/session.d.ts +14 -1
- package/mysql-core/session.js +80 -1
- package/mysql-core/session.js.map +1 -1
- package/mysql-core/utils.cjs +16 -0
- package/mysql-core/utils.cjs.map +1 -1
- package/mysql-core/utils.d.cts +6 -2
- package/mysql-core/utils.d.ts +6 -2
- package/mysql-core/utils.js +15 -0
- package/mysql-core/utils.js.map +1 -1
- package/mysql-proxy/session.cjs +15 -5
- package/mysql-proxy/session.cjs.map +1 -1
- package/mysql-proxy/session.d.cts +12 -2
- package/mysql-proxy/session.d.ts +12 -2
- package/mysql-proxy/session.js +15 -5
- package/mysql-proxy/session.js.map +1 -1
- package/mysql2/driver.cjs +11 -4
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +2 -0
- package/mysql2/driver.d.ts +2 -0
- package/mysql2/driver.js +11 -4
- package/mysql2/driver.js.map +1 -1
- package/mysql2/session.cjs +15 -5
- package/mysql2/session.cjs.map +1 -1
- package/mysql2/session.d.cts +12 -2
- package/mysql2/session.d.ts +12 -2
- package/mysql2/session.js +15 -5
- package/mysql2/session.js.map +1 -1
- package/neon-http/driver.cjs +13 -10
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +2 -0
- package/neon-http/driver.d.ts +2 -0
- package/neon-http/driver.js +13 -10
- package/neon-http/driver.js.map +1 -1
- package/neon-http/session.cjs +25 -15
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +12 -2
- package/neon-http/session.d.ts +12 -2
- package/neon-http/session.js +25 -15
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +10 -4
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +2 -0
- package/neon-serverless/driver.d.ts +2 -0
- package/neon-serverless/driver.js +10 -4
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/session.cjs +21 -7
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +12 -2
- package/neon-serverless/session.d.ts +12 -2
- package/neon-serverless/session.js +21 -7
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/driver.cjs +10 -4
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +2 -0
- package/node-postgres/driver.d.ts +2 -0
- package/node-postgres/driver.js +10 -4
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/session.cjs +19 -6
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +13 -2
- package/node-postgres/session.d.ts +13 -2
- package/node-postgres/session.js +19 -6
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +5 -1
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.js +5 -1
- package/op-sqlite/driver.js.map +1 -1
- package/op-sqlite/session.cjs +23 -9
- package/op-sqlite/session.cjs.map +1 -1
- package/op-sqlite/session.d.cts +12 -2
- package/op-sqlite/session.d.ts +12 -2
- package/op-sqlite/session.js +23 -9
- package/op-sqlite/session.js.map +1 -1
- package/package.json +77 -12
- package/pg-core/columns/common.cjs +1 -2
- package/pg-core/columns/common.cjs.map +1 -1
- package/pg-core/columns/common.js +1 -2
- package/pg-core/columns/common.js.map +1 -1
- package/pg-core/columns/numeric.cjs +2 -4
- package/pg-core/columns/numeric.cjs.map +1 -1
- package/pg-core/columns/numeric.js +2 -4
- package/pg-core/columns/numeric.js.map +1 -1
- package/pg-core/db.cjs +3 -0
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +4 -0
- package/pg-core/db.d.ts +4 -0
- package/pg-core/db.js +3 -0
- package/pg-core/db.js.map +1 -1
- package/pg-core/dialect.cjs +1 -2
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +1 -2
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/delete.cjs +6 -1
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +3 -1
- package/pg-core/query-builders/delete.d.ts +3 -1
- package/pg-core/query-builders/delete.js +6 -1
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +6 -1
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +2 -0
- package/pg-core/query-builders/insert.d.ts +2 -0
- package/pg-core/query-builders/insert.js +6 -1
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/select.cjs +28 -5
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +15 -6
- package/pg-core/query-builders/select.d.ts +15 -6
- package/pg-core/query-builders/select.js +28 -5
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/update.cjs +6 -1
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +4 -2
- package/pg-core/query-builders/update.d.ts +4 -2
- package/pg-core/query-builders/update.js +6 -1
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-core/session.cjs +78 -1
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +13 -2
- package/pg-core/session.d.ts +13 -2
- package/pg-core/session.js +79 -2
- package/pg-core/session.js.map +1 -1
- package/pg-core/utils.cjs +16 -0
- package/pg-core/utils.cjs.map +1 -1
- package/pg-core/utils.d.cts +8 -4
- package/pg-core/utils.d.ts +8 -4
- package/pg-core/utils.js +16 -1
- package/pg-core/utils.js.map +1 -1
- package/pg-proxy/driver.cjs +7 -2
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.js +7 -2
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/session.cjs +15 -5
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +12 -2
- package/pg-proxy/session.d.ts +12 -2
- package/pg-proxy/session.js +15 -5
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +10 -4
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +2 -0
- package/pglite/driver.d.ts +2 -0
- package/pglite/driver.js +10 -4
- package/pglite/driver.js.map +1 -1
- package/pglite/session.cjs +19 -7
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +12 -2
- package/pglite/session.d.ts +12 -2
- package/pglite/session.js +19 -7
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +6 -3
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +1 -0
- package/planetscale-serverless/driver.d.ts +1 -0
- package/planetscale-serverless/driver.js +6 -3
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/session.cjs +15 -5
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +12 -2
- package/planetscale-serverless/session.d.ts +12 -2
- package/planetscale-serverless/session.js +15 -5
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +6 -3
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.js +6 -3
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/session.cjs +18 -6
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +12 -2
- package/postgres-js/session.d.ts +12 -2
- package/postgres-js/session.js +18 -6
- package/postgres-js/session.js.map +1 -1
- package/prisma/mysql/session.cjs +1 -1
- package/prisma/mysql/session.cjs.map +1 -1
- package/prisma/mysql/session.js +1 -1
- package/prisma/mysql/session.js.map +1 -1
- package/prisma/pg/session.cjs +1 -1
- package/prisma/pg/session.cjs.map +1 -1
- package/prisma/pg/session.js +1 -1
- package/prisma/pg/session.js.map +1 -1
- package/query-builders/query-builder.cjs.map +1 -1
- package/query-builders/query-builder.d.cts +2 -1
- package/query-builders/query-builder.d.ts +2 -1
- package/query-builders/query-builder.js.map +1 -1
- package/singlestore/driver.cjs +13 -4
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +2 -0
- package/singlestore/driver.d.ts +2 -0
- package/singlestore/driver.js +13 -4
- package/singlestore/driver.js.map +1 -1
- package/singlestore/session.cjs +15 -5
- package/singlestore/session.cjs.map +1 -1
- package/singlestore/session.d.cts +12 -2
- package/singlestore/session.d.ts +12 -2
- package/singlestore/session.js +15 -5
- package/singlestore/session.js.map +1 -1
- package/singlestore-core/columns/binary.cjs +2 -4
- package/singlestore-core/columns/binary.cjs.map +1 -1
- package/singlestore-core/columns/binary.js +2 -4
- package/singlestore-core/columns/binary.js.map +1 -1
- package/singlestore-core/columns/decimal.cjs +2 -4
- package/singlestore-core/columns/decimal.cjs.map +1 -1
- package/singlestore-core/columns/decimal.js +2 -4
- package/singlestore-core/columns/decimal.js.map +1 -1
- package/singlestore-core/columns/varbinary.cjs +2 -4
- package/singlestore-core/columns/varbinary.cjs.map +1 -1
- package/singlestore-core/columns/varbinary.js +2 -4
- package/singlestore-core/columns/varbinary.js.map +1 -1
- package/singlestore-core/db.cjs +3 -0
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +4 -0
- package/singlestore-core/db.d.ts +4 -0
- package/singlestore-core/db.js +3 -0
- package/singlestore-core/db.js.map +1 -1
- package/singlestore-core/dialect.cjs +1 -2
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.js +1 -2
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/delete.cjs +9 -1
- package/singlestore-core/query-builders/delete.cjs.map +1 -1
- package/singlestore-core/query-builders/delete.js +9 -1
- package/singlestore-core/query-builders/delete.js.map +1 -1
- package/singlestore-core/query-builders/insert.cjs +6 -1
- package/singlestore-core/query-builders/insert.cjs.map +1 -1
- package/singlestore-core/query-builders/insert.js +6 -1
- package/singlestore-core/query-builders/insert.js.map +1 -1
- package/singlestore-core/query-builders/select.cjs +25 -3
- package/singlestore-core/query-builders/select.cjs.map +1 -1
- package/singlestore-core/query-builders/select.d.cts +9 -0
- package/singlestore-core/query-builders/select.d.ts +9 -0
- package/singlestore-core/query-builders/select.js +25 -3
- package/singlestore-core/query-builders/select.js.map +1 -1
- package/singlestore-core/query-builders/update.cjs +9 -1
- package/singlestore-core/query-builders/update.cjs.map +1 -1
- package/singlestore-core/query-builders/update.js +9 -1
- package/singlestore-core/query-builders/update.js.map +1 -1
- package/singlestore-core/session.cjs +79 -0
- package/singlestore-core/session.cjs.map +1 -1
- package/singlestore-core/session.d.cts +13 -1
- package/singlestore-core/session.d.ts +13 -1
- package/singlestore-core/session.js +80 -1
- package/singlestore-core/session.js.map +1 -1
- package/singlestore-core/utils.cjs +16 -0
- package/singlestore-core/utils.cjs.map +1 -1
- package/singlestore-core/utils.d.cts +3 -0
- package/singlestore-core/utils.d.ts +3 -0
- package/singlestore-core/utils.js +15 -0
- package/singlestore-core/utils.js.map +1 -1
- package/sql/sql.cjs +10 -0
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.js +10 -0
- package/sql/sql.js.map +1 -1
- package/sqlite-core/columns/numeric.cjs +2 -4
- package/sqlite-core/columns/numeric.cjs.map +1 -1
- package/sqlite-core/columns/numeric.js +2 -4
- package/sqlite-core/columns/numeric.js.map +1 -1
- package/sqlite-core/db.cjs +3 -0
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +4 -0
- package/sqlite-core/db.d.ts +4 -0
- package/sqlite-core/db.js +3 -0
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/dialect.cjs +1 -2
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +1 -2
- package/sqlite-core/dialect.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +7 -1
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.js +7 -1
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +9 -5
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.js +9 -5
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +28 -3
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +9 -0
- package/sqlite-core/query-builders/select.d.ts +9 -0
- package/sqlite-core/query-builders/select.js +28 -3
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/update.cjs +7 -1
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.js +7 -1
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/sqlite-core/session.cjs +88 -3
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +18 -4
- package/sqlite-core/session.d.ts +18 -4
- package/sqlite-core/session.js +89 -4
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-core/utils.cjs +16 -0
- package/sqlite-core/utils.cjs.map +1 -1
- package/sqlite-core/utils.d.cts +6 -2
- package/sqlite-core/utils.d.ts +6 -2
- package/sqlite-core/utils.js +15 -0
- package/sqlite-core/utils.js.map +1 -1
- package/sqlite-proxy/driver.cjs +9 -2
- package/sqlite-proxy/driver.cjs.map +1 -1
- package/sqlite-proxy/driver.js +9 -2
- package/sqlite-proxy/driver.js.map +1 -1
- package/sqlite-proxy/session.cjs +22 -8
- package/sqlite-proxy/session.cjs.map +1 -1
- package/sqlite-proxy/session.d.cts +12 -2
- package/sqlite-proxy/session.d.ts +12 -2
- package/sqlite-proxy/session.js +22 -8
- package/sqlite-proxy/session.js.map +1 -1
- package/subquery.cjs +4 -3
- package/subquery.cjs.map +1 -1
- package/subquery.d.cts +2 -1
- package/subquery.d.ts +2 -1
- package/subquery.js +4 -3
- package/subquery.js.map +1 -1
- package/tidb-serverless/driver.cjs +6 -3
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +1 -0
- package/tidb-serverless/driver.d.ts +1 -0
- package/tidb-serverless/driver.js +6 -3
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +15 -5
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +12 -2
- package/tidb-serverless/session.d.ts +12 -2
- package/tidb-serverless/session.js +15 -5
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs +10 -20
- package/utils.cjs.map +1 -1
- package/utils.d.cts +2 -0
- package/utils.d.ts +2 -0
- package/utils.js +10 -20
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +9 -2
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +2 -0
- package/vercel-postgres/driver.d.ts +2 -0
- package/vercel-postgres/driver.js +9 -2
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/session.cjs +21 -7
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +12 -2
- package/vercel-postgres/session.d.ts +12 -2
- package/vercel-postgres/session.js +21 -7
- package/vercel-postgres/session.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/xata-http/driver.cjs +7 -2
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +2 -0
- package/xata-http/driver.d.ts +2 -0
- package/xata-http/driver.js +7 -2
- package/xata-http/driver.js.map +1 -1
- package/xata-http/session.cjs +22 -9
- package/xata-http/session.cjs.map +1 -1
- package/xata-http/session.d.cts +12 -2
- package/xata-http/session.d.ts +12 -2
- package/xata-http/session.js +22 -9
- package/xata-http/session.js.map +1 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
UpstashCache: () => UpstashCache,
|
|
22
|
+
upstashCache: () => upstashCache
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cache_exports);
|
|
25
|
+
var import_redis = require("@upstash/redis");
|
|
26
|
+
var import_core = require("../core/index.cjs");
|
|
27
|
+
var import_entity = require("../../entity.cjs");
|
|
28
|
+
var import__ = require("../../index.cjs");
|
|
29
|
+
const getByTagScript = `
|
|
30
|
+
local tagsMapKey = KEYS[1] -- tags map key
|
|
31
|
+
local tag = ARGV[1] -- tag
|
|
32
|
+
|
|
33
|
+
local compositeTableName = redis.call('HGET', tagsMapKey, tag)
|
|
34
|
+
if not compositeTableName then
|
|
35
|
+
return nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
local value = redis.call('HGET', compositeTableName, tag)
|
|
39
|
+
return value
|
|
40
|
+
`;
|
|
41
|
+
const onMutateScript = `
|
|
42
|
+
local tagsMapKey = KEYS[1] -- tags map key
|
|
43
|
+
local tables = {} -- initialize tables array
|
|
44
|
+
local tags = ARGV -- tags array
|
|
45
|
+
|
|
46
|
+
for i = 2, #KEYS do
|
|
47
|
+
tables[#tables + 1] = KEYS[i] -- add all keys except the first one to tables
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if #tags > 0 then
|
|
51
|
+
for _, tag in ipairs(tags) do
|
|
52
|
+
if tag ~= nil and tag ~= '' then
|
|
53
|
+
local compositeTableName = redis.call('HGET', tagsMapKey, tag)
|
|
54
|
+
if compositeTableName then
|
|
55
|
+
redis.call('HDEL', compositeTableName, tag)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
redis.call('HDEL', tagsMapKey, unpack(tags))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
local keysToDelete = {}
|
|
63
|
+
|
|
64
|
+
if #tables > 0 then
|
|
65
|
+
local compositeTableNames = redis.call('SUNION', unpack(tables))
|
|
66
|
+
for _, compositeTableName in ipairs(compositeTableNames) do
|
|
67
|
+
keysToDelete[#keysToDelete + 1] = compositeTableName
|
|
68
|
+
end
|
|
69
|
+
for _, table in ipairs(tables) do
|
|
70
|
+
keysToDelete[#keysToDelete + 1] = table
|
|
71
|
+
end
|
|
72
|
+
redis.call('DEL', unpack(keysToDelete))
|
|
73
|
+
end
|
|
74
|
+
`;
|
|
75
|
+
class UpstashCache extends import_core.Cache {
|
|
76
|
+
constructor(redis, config, useGlobally) {
|
|
77
|
+
super();
|
|
78
|
+
this.redis = redis;
|
|
79
|
+
this.useGlobally = useGlobally;
|
|
80
|
+
this.internalConfig = this.toInternalConfig(config);
|
|
81
|
+
this.luaScripts = {
|
|
82
|
+
getByTagScript: this.redis.createScript(getByTagScript, { readonly: true }),
|
|
83
|
+
onMutateScript: this.redis.createScript(onMutateScript)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
static [import_entity.entityKind] = "UpstashCache";
|
|
87
|
+
/**
|
|
88
|
+
* Prefix for sets which denote the composite table names for each unique table
|
|
89
|
+
*
|
|
90
|
+
* Example: In the composite table set of "table1", you may find
|
|
91
|
+
* `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`
|
|
92
|
+
*/
|
|
93
|
+
static compositeTableSetPrefix = "__CTS__";
|
|
94
|
+
/**
|
|
95
|
+
* Prefix for hashes which map hash or tags to cache values
|
|
96
|
+
*/
|
|
97
|
+
static compositeTablePrefix = "__CT__";
|
|
98
|
+
/**
|
|
99
|
+
* Key which holds the mapping of tags to composite table names
|
|
100
|
+
*
|
|
101
|
+
* Using this tagsMapKey, you can find the composite table name for a given tag
|
|
102
|
+
* and get the cache value for that tag:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* const compositeTable = redis.hget(tagsMapKey, 'tag1')
|
|
106
|
+
* console.log(compositeTable) // `${compositeTablePrefix}table1,table2`
|
|
107
|
+
*
|
|
108
|
+
* const cachevalue = redis.hget(compositeTable, 'tag1')
|
|
109
|
+
*/
|
|
110
|
+
static tagsMapKey = "__tagsMap__";
|
|
111
|
+
/**
|
|
112
|
+
* Queries whose auto invalidation is false aren't stored in their respective
|
|
113
|
+
* composite table hashes because those hashes are deleted when a mutation
|
|
114
|
+
* occurs on related tables.
|
|
115
|
+
*
|
|
116
|
+
* Instead, they are stored in a separate hash with the prefix
|
|
117
|
+
* `__nonAutoInvalidate__` to prevent them from being deleted when a mutation
|
|
118
|
+
*/
|
|
119
|
+
static nonAutoInvalidateTablePrefix = "__nonAutoInvalidate__";
|
|
120
|
+
luaScripts;
|
|
121
|
+
internalConfig;
|
|
122
|
+
strategy() {
|
|
123
|
+
return this.useGlobally ? "all" : "explicit";
|
|
124
|
+
}
|
|
125
|
+
toInternalConfig(config) {
|
|
126
|
+
return config ? {
|
|
127
|
+
seconds: config.ex,
|
|
128
|
+
hexOptions: config.hexOptions
|
|
129
|
+
} : {
|
|
130
|
+
seconds: 1
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async get(key, tables, isTag = false, isAutoInvalidate) {
|
|
134
|
+
if (!isAutoInvalidate) {
|
|
135
|
+
const result2 = await this.redis.hget(UpstashCache.nonAutoInvalidateTablePrefix, key);
|
|
136
|
+
return result2 === null ? void 0 : result2;
|
|
137
|
+
}
|
|
138
|
+
if (isTag) {
|
|
139
|
+
const result2 = await this.luaScripts.getByTagScript.exec([UpstashCache.tagsMapKey], [key]);
|
|
140
|
+
return result2 === null ? void 0 : result2;
|
|
141
|
+
}
|
|
142
|
+
const compositeKey = this.getCompositeKey(tables);
|
|
143
|
+
const result = (await this.redis.hget(compositeKey, key)) ?? void 0;
|
|
144
|
+
return result === null ? void 0 : result;
|
|
145
|
+
}
|
|
146
|
+
async put(key, response, tables, isTag = false, config) {
|
|
147
|
+
const isAutoInvalidate = tables.length !== 0;
|
|
148
|
+
const pipeline = this.redis.pipeline();
|
|
149
|
+
const ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;
|
|
150
|
+
const hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;
|
|
151
|
+
if (!isAutoInvalidate) {
|
|
152
|
+
if (isTag) {
|
|
153
|
+
pipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });
|
|
154
|
+
pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
|
|
155
|
+
}
|
|
156
|
+
pipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });
|
|
157
|
+
pipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);
|
|
158
|
+
await pipeline.exec();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const compositeKey = this.getCompositeKey(tables);
|
|
162
|
+
pipeline.hset(compositeKey, { [key]: response });
|
|
163
|
+
pipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions);
|
|
164
|
+
if (isTag) {
|
|
165
|
+
pipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey });
|
|
166
|
+
pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
|
|
167
|
+
}
|
|
168
|
+
for (const table of tables) {
|
|
169
|
+
pipeline.sadd(this.addTablePrefix(table), compositeKey);
|
|
170
|
+
}
|
|
171
|
+
await pipeline.exec();
|
|
172
|
+
}
|
|
173
|
+
async onMutate(params) {
|
|
174
|
+
const tags = Array.isArray(params.tags) ? params.tags : params.tags ? [params.tags] : [];
|
|
175
|
+
const tables = Array.isArray(params.tables) ? params.tables : params.tables ? [params.tables] : [];
|
|
176
|
+
const tableNames = tables.map((table) => (0, import_entity.is)(table, import__.Table) ? table[import__.OriginalName] : table);
|
|
177
|
+
const compositeTableSets = tableNames.map((table) => this.addTablePrefix(table));
|
|
178
|
+
await this.luaScripts.onMutateScript.exec([UpstashCache.tagsMapKey, ...compositeTableSets], tags);
|
|
179
|
+
}
|
|
180
|
+
addTablePrefix = (table) => `${UpstashCache.compositeTableSetPrefix}${table}`;
|
|
181
|
+
getCompositeKey = (tables) => `${UpstashCache.compositeTablePrefix}${tables.sort().join(",")}`;
|
|
182
|
+
}
|
|
183
|
+
function upstashCache({ url, token, config, global = false }) {
|
|
184
|
+
const redis = new import_redis.Redis({
|
|
185
|
+
url,
|
|
186
|
+
token
|
|
187
|
+
});
|
|
188
|
+
return new UpstashCache(redis, config, global);
|
|
189
|
+
}
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {
|
|
192
|
+
UpstashCache,
|
|
193
|
+
upstashCache
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=cache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/cache/upstash/cache.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { MutationOption } from '~/cache/core/index.ts';\nimport { Cache } from '~/cache/core/index.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { OriginalName, Table } from '~/index.ts';\nimport type { CacheConfig } from '../core/types.ts';\n\nconst getByTagScript = `\nlocal tagsMapKey = KEYS[1] -- tags map key\nlocal tag = ARGV[1] -- tag\n\nlocal compositeTableName = redis.call('HGET', tagsMapKey, tag)\nif not compositeTableName then\n return nil\nend\n\nlocal value = redis.call('HGET', compositeTableName, tag)\nreturn value\n`;\n\nconst onMutateScript = `\nlocal tagsMapKey = KEYS[1] -- tags map key\nlocal tables = {} -- initialize tables array\nlocal tags = ARGV -- tags array\n\nfor i = 2, #KEYS do\n tables[#tables + 1] = KEYS[i] -- add all keys except the first one to tables\nend\n\nif #tags > 0 then\n for _, tag in ipairs(tags) do\n if tag ~= nil and tag ~= '' then\n local compositeTableName = redis.call('HGET', tagsMapKey, tag)\n if compositeTableName then\n redis.call('HDEL', compositeTableName, tag)\n end\n end\n end\n redis.call('HDEL', tagsMapKey, unpack(tags))\nend\n\nlocal keysToDelete = {}\n\nif #tables > 0 then\n local compositeTableNames = redis.call('SUNION', unpack(tables))\n for _, compositeTableName in ipairs(compositeTableNames) do\n keysToDelete[#keysToDelete + 1] = compositeTableName\n end\n for _, table in ipairs(tables) do\n keysToDelete[#keysToDelete + 1] = table\n end\n redis.call('DEL', unpack(keysToDelete))\nend\n`;\n\ntype Script = ReturnType<Redis['createScript']>;\n\ntype ExpireOptions = 'NX' | 'nx' | 'XX' | 'xx' | 'GT' | 'gt' | 'LT' | 'lt';\n\nexport class UpstashCache extends Cache {\n\tstatic override readonly [entityKind]: string = 'UpstashCache';\n\t/**\n\t * Prefix for sets which denote the composite table names for each unique table\n\t *\n\t * Example: In the composite table set of \"table1\", you may find\n\t * `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`\n\t */\n\tprivate static compositeTableSetPrefix = '__CTS__';\n\t/**\n\t * Prefix for hashes which map hash or tags to cache values\n\t */\n\tprivate static compositeTablePrefix = '__CT__';\n\t/**\n\t * Key which holds the mapping of tags to composite table names\n\t *\n\t * Using this tagsMapKey, you can find the composite table name for a given tag\n\t * and get the cache value for that tag:\n\t *\n\t * ```ts\n\t * const compositeTable = redis.hget(tagsMapKey, 'tag1')\n\t * console.log(compositeTable) // `${compositeTablePrefix}table1,table2`\n\t *\n\t * const cachevalue = redis.hget(compositeTable, 'tag1')\n\t */\n\tprivate static tagsMapKey = '__tagsMap__';\n\t/**\n\t * Queries whose auto invalidation is false aren't stored in their respective\n\t * composite table hashes because those hashes are deleted when a mutation\n\t * occurs on related tables.\n\t *\n\t * Instead, they are stored in a separate hash with the prefix\n\t * `__nonAutoInvalidate__` to prevent them from being deleted when a mutation\n\t */\n\tprivate static nonAutoInvalidateTablePrefix = '__nonAutoInvalidate__';\n\n\tprivate luaScripts: {\n\t\tgetByTagScript: Script;\n\t\tonMutateScript: Script;\n\t};\n\n\tprivate internalConfig: { seconds: number; hexOptions?: ExpireOptions };\n\n\tconstructor(public redis: Redis, config?: CacheConfig, protected useGlobally?: boolean) {\n\t\tsuper();\n\t\tthis.internalConfig = this.toInternalConfig(config);\n\t\tthis.luaScripts = {\n\t\t\tgetByTagScript: this.redis.createScript(getByTagScript, { readonly: true }),\n\t\t\tonMutateScript: this.redis.createScript(onMutateScript),\n\t\t};\n\t}\n\n\tpublic strategy() {\n\t\treturn this.useGlobally ? 'all' : 'explicit';\n\t}\n\n\tprivate toInternalConfig(config?: CacheConfig): { seconds: number; hexOptions?: ExpireOptions } {\n\t\treturn config\n\t\t\t? {\n\t\t\t\tseconds: config.ex!,\n\t\t\t\thexOptions: config.hexOptions,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tseconds: 1,\n\t\t\t};\n\t}\n\n\toverride async get(\n\t\tkey: string,\n\t\ttables: string[],\n\t\tisTag: boolean = false,\n\t\tisAutoInvalidate?: boolean,\n\t): Promise<any[] | undefined> {\n\t\tif (!isAutoInvalidate) {\n\t\t\tconst result = await this.redis.hget(UpstashCache.nonAutoInvalidateTablePrefix, key);\n\t\t\treturn result === null ? undefined : result as any[];\n\t\t}\n\n\t\tif (isTag) {\n\t\t\tconst result = await this.luaScripts.getByTagScript.exec([UpstashCache.tagsMapKey], [key]);\n\t\t\treturn result === null ? undefined : result as any[];\n\t\t}\n\n\t\t// Normal cache lookup for the composite key\n\t\tconst compositeKey = this.getCompositeKey(tables);\n\t\tconst result = await this.redis.hget(compositeKey, key) ?? undefined; // Retrieve result for normal query\n\t\treturn result === null ? undefined : result as any[];\n\t}\n\n\toverride async put(\n\t\tkey: string,\n\t\tresponse: any,\n\t\ttables: string[],\n\t\tisTag: boolean = false,\n\t\tconfig?: CacheConfig,\n\t): Promise<void> {\n\t\tconst isAutoInvalidate = tables.length !== 0;\n\n\t\tconst pipeline = this.redis.pipeline();\n\t\tconst ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;\n\t\tconst hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;\n\n\t\tif (!isAutoInvalidate) {\n\t\t\tif (isTag) {\n\t\t\t\tpipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });\n\t\t\t\tpipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);\n\t\t\t}\n\n\t\t\tpipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });\n\t\t\tpipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);\n\t\t\tawait pipeline.exec();\n\t\t\treturn;\n\t\t}\n\n\t\tconst compositeKey = this.getCompositeKey(tables);\n\n\t\tpipeline.hset(compositeKey, { [key]: response }); // Store the result with the tag under the composite key\n\t\tpipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions); // Set expiration for the composite key\n\n\t\tif (isTag) {\n\t\t\tpipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey }); // Store the tag and its composite key in the map\n\t\t\tpipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions); // Set expiration for the tag\n\t\t}\n\n\t\tfor (const table of tables) {\n\t\t\tpipeline.sadd(this.addTablePrefix(table), compositeKey);\n\t\t}\n\n\t\tawait pipeline.exec();\n\t}\n\n\toverride async onMutate(params: MutationOption) {\n\t\tconst tags = Array.isArray(params.tags) ? params.tags : params.tags ? [params.tags] : [];\n\t\tconst tables = Array.isArray(params.tables) ? params.tables : params.tables ? [params.tables] : [];\n\t\tconst tableNames: string[] = tables.map((table) => is(table, Table) ? table[OriginalName] : table as string);\n\n\t\tconst compositeTableSets = tableNames.map((table) => this.addTablePrefix(table));\n\t\tawait this.luaScripts.onMutateScript.exec([UpstashCache.tagsMapKey, ...compositeTableSets], tags);\n\t}\n\n\tprivate addTablePrefix = (table: string) => `${UpstashCache.compositeTableSetPrefix}${table}`;\n\tprivate getCompositeKey = (tables: string[]) => `${UpstashCache.compositeTablePrefix}${tables.sort().join(',')}`;\n}\n\nexport function upstashCache(\n\t{ url, token, config, global = false }: { url: string; token: string; config?: CacheConfig; global?: boolean },\n): UpstashCache {\n\tconst redis = new Redis({\n\t\turl,\n\t\ttoken,\n\t});\n\n\treturn new UpstashCache(redis, config, global);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAEtB,kBAAsB;AACtB,oBAA+B;AAC/B,eAAoC;AAGpC,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAavB,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuChB,MAAM,qBAAqB,kBAAM;AAAA,EA2CvC,YAAmB,OAAc,QAAgC,aAAuB;AACvF,UAAM;AADY;AAA8C;AAEhE,SAAK,iBAAiB,KAAK,iBAAiB,MAAM;AAClD,SAAK,aAAa;AAAA,MACjB,gBAAgB,KAAK,MAAM,aAAa,gBAAgB,EAAE,UAAU,KAAK,CAAC;AAAA,MAC1E,gBAAgB,KAAK,MAAM,aAAa,cAAc;AAAA,IACvD;AAAA,EACD;AAAA,EAjDA,QAA0B,wBAAU,IAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhD,OAAe,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAIzC,OAAe,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAatC,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AK,GAAG,CAAC;AAC/G;AAEO,SAAS,aACf,EAAE,KAAK,OAAO,QAAQ,SAAS,MAAM,GACtB;AACf,QAAM,QAAQ,IAAI,mBAAM;AAAA,IACvB;AAAA,IACA;AAAA,EACD,CAAC;AAED,SAAO,IAAI,aAAa,OAAO,QAAQ,MAAM;AAC9C;","names":["result"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Redis } from '@upstash/redis';
|
|
2
|
+
import type { MutationOption } from "../core/index.cjs";
|
|
3
|
+
import { Cache } from "../core/index.cjs";
|
|
4
|
+
import { entityKind } from "../../entity.cjs";
|
|
5
|
+
import type { CacheConfig } from "../core/types.cjs";
|
|
6
|
+
export declare class UpstashCache extends Cache {
|
|
7
|
+
redis: Redis;
|
|
8
|
+
protected useGlobally?: boolean | undefined;
|
|
9
|
+
static readonly [entityKind]: string;
|
|
10
|
+
/**
|
|
11
|
+
* Prefix for sets which denote the composite table names for each unique table
|
|
12
|
+
*
|
|
13
|
+
* Example: In the composite table set of "table1", you may find
|
|
14
|
+
* `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`
|
|
15
|
+
*/
|
|
16
|
+
private static compositeTableSetPrefix;
|
|
17
|
+
/**
|
|
18
|
+
* Prefix for hashes which map hash or tags to cache values
|
|
19
|
+
*/
|
|
20
|
+
private static compositeTablePrefix;
|
|
21
|
+
/**
|
|
22
|
+
* Key which holds the mapping of tags to composite table names
|
|
23
|
+
*
|
|
24
|
+
* Using this tagsMapKey, you can find the composite table name for a given tag
|
|
25
|
+
* and get the cache value for that tag:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const compositeTable = redis.hget(tagsMapKey, 'tag1')
|
|
29
|
+
* console.log(compositeTable) // `${compositeTablePrefix}table1,table2`
|
|
30
|
+
*
|
|
31
|
+
* const cachevalue = redis.hget(compositeTable, 'tag1')
|
|
32
|
+
*/
|
|
33
|
+
private static tagsMapKey;
|
|
34
|
+
/**
|
|
35
|
+
* Queries whose auto invalidation is false aren't stored in their respective
|
|
36
|
+
* composite table hashes because those hashes are deleted when a mutation
|
|
37
|
+
* occurs on related tables.
|
|
38
|
+
*
|
|
39
|
+
* Instead, they are stored in a separate hash with the prefix
|
|
40
|
+
* `__nonAutoInvalidate__` to prevent them from being deleted when a mutation
|
|
41
|
+
*/
|
|
42
|
+
private static nonAutoInvalidateTablePrefix;
|
|
43
|
+
private luaScripts;
|
|
44
|
+
private internalConfig;
|
|
45
|
+
constructor(redis: Redis, config?: CacheConfig, useGlobally?: boolean | undefined);
|
|
46
|
+
strategy(): "all" | "explicit";
|
|
47
|
+
private toInternalConfig;
|
|
48
|
+
get(key: string, tables: string[], isTag?: boolean, isAutoInvalidate?: boolean): Promise<any[] | undefined>;
|
|
49
|
+
put(key: string, response: any, tables: string[], isTag?: boolean, config?: CacheConfig): Promise<void>;
|
|
50
|
+
onMutate(params: MutationOption): Promise<void>;
|
|
51
|
+
private addTablePrefix;
|
|
52
|
+
private getCompositeKey;
|
|
53
|
+
}
|
|
54
|
+
export declare function upstashCache({ url, token, config, global }: {
|
|
55
|
+
url: string;
|
|
56
|
+
token: string;
|
|
57
|
+
config?: CacheConfig;
|
|
58
|
+
global?: boolean;
|
|
59
|
+
}): UpstashCache;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Redis } from '@upstash/redis';
|
|
2
|
+
import type { MutationOption } from "../core/index.js";
|
|
3
|
+
import { Cache } from "../core/index.js";
|
|
4
|
+
import { entityKind } from "../../entity.js";
|
|
5
|
+
import type { CacheConfig } from "../core/types.js";
|
|
6
|
+
export declare class UpstashCache extends Cache {
|
|
7
|
+
redis: Redis;
|
|
8
|
+
protected useGlobally?: boolean | undefined;
|
|
9
|
+
static readonly [entityKind]: string;
|
|
10
|
+
/**
|
|
11
|
+
* Prefix for sets which denote the composite table names for each unique table
|
|
12
|
+
*
|
|
13
|
+
* Example: In the composite table set of "table1", you may find
|
|
14
|
+
* `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`
|
|
15
|
+
*/
|
|
16
|
+
private static compositeTableSetPrefix;
|
|
17
|
+
/**
|
|
18
|
+
* Prefix for hashes which map hash or tags to cache values
|
|
19
|
+
*/
|
|
20
|
+
private static compositeTablePrefix;
|
|
21
|
+
/**
|
|
22
|
+
* Key which holds the mapping of tags to composite table names
|
|
23
|
+
*
|
|
24
|
+
* Using this tagsMapKey, you can find the composite table name for a given tag
|
|
25
|
+
* and get the cache value for that tag:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const compositeTable = redis.hget(tagsMapKey, 'tag1')
|
|
29
|
+
* console.log(compositeTable) // `${compositeTablePrefix}table1,table2`
|
|
30
|
+
*
|
|
31
|
+
* const cachevalue = redis.hget(compositeTable, 'tag1')
|
|
32
|
+
*/
|
|
33
|
+
private static tagsMapKey;
|
|
34
|
+
/**
|
|
35
|
+
* Queries whose auto invalidation is false aren't stored in their respective
|
|
36
|
+
* composite table hashes because those hashes are deleted when a mutation
|
|
37
|
+
* occurs on related tables.
|
|
38
|
+
*
|
|
39
|
+
* Instead, they are stored in a separate hash with the prefix
|
|
40
|
+
* `__nonAutoInvalidate__` to prevent them from being deleted when a mutation
|
|
41
|
+
*/
|
|
42
|
+
private static nonAutoInvalidateTablePrefix;
|
|
43
|
+
private luaScripts;
|
|
44
|
+
private internalConfig;
|
|
45
|
+
constructor(redis: Redis, config?: CacheConfig, useGlobally?: boolean | undefined);
|
|
46
|
+
strategy(): "all" | "explicit";
|
|
47
|
+
private toInternalConfig;
|
|
48
|
+
get(key: string, tables: string[], isTag?: boolean, isAutoInvalidate?: boolean): Promise<any[] | undefined>;
|
|
49
|
+
put(key: string, response: any, tables: string[], isTag?: boolean, config?: CacheConfig): Promise<void>;
|
|
50
|
+
onMutate(params: MutationOption): Promise<void>;
|
|
51
|
+
private addTablePrefix;
|
|
52
|
+
private getCompositeKey;
|
|
53
|
+
}
|
|
54
|
+
export declare function upstashCache({ url, token, config, global }: {
|
|
55
|
+
url: string;
|
|
56
|
+
token: string;
|
|
57
|
+
config?: CacheConfig;
|
|
58
|
+
global?: boolean;
|
|
59
|
+
}): UpstashCache;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Redis } from "@upstash/redis";
|
|
2
|
+
import { Cache } from "../core/index.js";
|
|
3
|
+
import { entityKind, is } from "../../entity.js";
|
|
4
|
+
import { OriginalName, Table } from "../../index.js";
|
|
5
|
+
const getByTagScript = `
|
|
6
|
+
local tagsMapKey = KEYS[1] -- tags map key
|
|
7
|
+
local tag = ARGV[1] -- tag
|
|
8
|
+
|
|
9
|
+
local compositeTableName = redis.call('HGET', tagsMapKey, tag)
|
|
10
|
+
if not compositeTableName then
|
|
11
|
+
return nil
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
local value = redis.call('HGET', compositeTableName, tag)
|
|
15
|
+
return value
|
|
16
|
+
`;
|
|
17
|
+
const onMutateScript = `
|
|
18
|
+
local tagsMapKey = KEYS[1] -- tags map key
|
|
19
|
+
local tables = {} -- initialize tables array
|
|
20
|
+
local tags = ARGV -- tags array
|
|
21
|
+
|
|
22
|
+
for i = 2, #KEYS do
|
|
23
|
+
tables[#tables + 1] = KEYS[i] -- add all keys except the first one to tables
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if #tags > 0 then
|
|
27
|
+
for _, tag in ipairs(tags) do
|
|
28
|
+
if tag ~= nil and tag ~= '' then
|
|
29
|
+
local compositeTableName = redis.call('HGET', tagsMapKey, tag)
|
|
30
|
+
if compositeTableName then
|
|
31
|
+
redis.call('HDEL', compositeTableName, tag)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
redis.call('HDEL', tagsMapKey, unpack(tags))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
local keysToDelete = {}
|
|
39
|
+
|
|
40
|
+
if #tables > 0 then
|
|
41
|
+
local compositeTableNames = redis.call('SUNION', unpack(tables))
|
|
42
|
+
for _, compositeTableName in ipairs(compositeTableNames) do
|
|
43
|
+
keysToDelete[#keysToDelete + 1] = compositeTableName
|
|
44
|
+
end
|
|
45
|
+
for _, table in ipairs(tables) do
|
|
46
|
+
keysToDelete[#keysToDelete + 1] = table
|
|
47
|
+
end
|
|
48
|
+
redis.call('DEL', unpack(keysToDelete))
|
|
49
|
+
end
|
|
50
|
+
`;
|
|
51
|
+
class UpstashCache extends Cache {
|
|
52
|
+
constructor(redis, config, useGlobally) {
|
|
53
|
+
super();
|
|
54
|
+
this.redis = redis;
|
|
55
|
+
this.useGlobally = useGlobally;
|
|
56
|
+
this.internalConfig = this.toInternalConfig(config);
|
|
57
|
+
this.luaScripts = {
|
|
58
|
+
getByTagScript: this.redis.createScript(getByTagScript, { readonly: true }),
|
|
59
|
+
onMutateScript: this.redis.createScript(onMutateScript)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static [entityKind] = "UpstashCache";
|
|
63
|
+
/**
|
|
64
|
+
* Prefix for sets which denote the composite table names for each unique table
|
|
65
|
+
*
|
|
66
|
+
* Example: In the composite table set of "table1", you may find
|
|
67
|
+
* `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`
|
|
68
|
+
*/
|
|
69
|
+
static compositeTableSetPrefix = "__CTS__";
|
|
70
|
+
/**
|
|
71
|
+
* Prefix for hashes which map hash or tags to cache values
|
|
72
|
+
*/
|
|
73
|
+
static compositeTablePrefix = "__CT__";
|
|
74
|
+
/**
|
|
75
|
+
* Key which holds the mapping of tags to composite table names
|
|
76
|
+
*
|
|
77
|
+
* Using this tagsMapKey, you can find the composite table name for a given tag
|
|
78
|
+
* and get the cache value for that tag:
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* const compositeTable = redis.hget(tagsMapKey, 'tag1')
|
|
82
|
+
* console.log(compositeTable) // `${compositeTablePrefix}table1,table2`
|
|
83
|
+
*
|
|
84
|
+
* const cachevalue = redis.hget(compositeTable, 'tag1')
|
|
85
|
+
*/
|
|
86
|
+
static tagsMapKey = "__tagsMap__";
|
|
87
|
+
/**
|
|
88
|
+
* Queries whose auto invalidation is false aren't stored in their respective
|
|
89
|
+
* composite table hashes because those hashes are deleted when a mutation
|
|
90
|
+
* occurs on related tables.
|
|
91
|
+
*
|
|
92
|
+
* Instead, they are stored in a separate hash with the prefix
|
|
93
|
+
* `__nonAutoInvalidate__` to prevent them from being deleted when a mutation
|
|
94
|
+
*/
|
|
95
|
+
static nonAutoInvalidateTablePrefix = "__nonAutoInvalidate__";
|
|
96
|
+
luaScripts;
|
|
97
|
+
internalConfig;
|
|
98
|
+
strategy() {
|
|
99
|
+
return this.useGlobally ? "all" : "explicit";
|
|
100
|
+
}
|
|
101
|
+
toInternalConfig(config) {
|
|
102
|
+
return config ? {
|
|
103
|
+
seconds: config.ex,
|
|
104
|
+
hexOptions: config.hexOptions
|
|
105
|
+
} : {
|
|
106
|
+
seconds: 1
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async get(key, tables, isTag = false, isAutoInvalidate) {
|
|
110
|
+
if (!isAutoInvalidate) {
|
|
111
|
+
const result2 = await this.redis.hget(UpstashCache.nonAutoInvalidateTablePrefix, key);
|
|
112
|
+
return result2 === null ? void 0 : result2;
|
|
113
|
+
}
|
|
114
|
+
if (isTag) {
|
|
115
|
+
const result2 = await this.luaScripts.getByTagScript.exec([UpstashCache.tagsMapKey], [key]);
|
|
116
|
+
return result2 === null ? void 0 : result2;
|
|
117
|
+
}
|
|
118
|
+
const compositeKey = this.getCompositeKey(tables);
|
|
119
|
+
const result = (await this.redis.hget(compositeKey, key)) ?? void 0;
|
|
120
|
+
return result === null ? void 0 : result;
|
|
121
|
+
}
|
|
122
|
+
async put(key, response, tables, isTag = false, config) {
|
|
123
|
+
const isAutoInvalidate = tables.length !== 0;
|
|
124
|
+
const pipeline = this.redis.pipeline();
|
|
125
|
+
const ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;
|
|
126
|
+
const hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;
|
|
127
|
+
if (!isAutoInvalidate) {
|
|
128
|
+
if (isTag) {
|
|
129
|
+
pipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });
|
|
130
|
+
pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
|
|
131
|
+
}
|
|
132
|
+
pipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });
|
|
133
|
+
pipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);
|
|
134
|
+
await pipeline.exec();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const compositeKey = this.getCompositeKey(tables);
|
|
138
|
+
pipeline.hset(compositeKey, { [key]: response });
|
|
139
|
+
pipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions);
|
|
140
|
+
if (isTag) {
|
|
141
|
+
pipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey });
|
|
142
|
+
pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
|
|
143
|
+
}
|
|
144
|
+
for (const table of tables) {
|
|
145
|
+
pipeline.sadd(this.addTablePrefix(table), compositeKey);
|
|
146
|
+
}
|
|
147
|
+
await pipeline.exec();
|
|
148
|
+
}
|
|
149
|
+
async onMutate(params) {
|
|
150
|
+
const tags = Array.isArray(params.tags) ? params.tags : params.tags ? [params.tags] : [];
|
|
151
|
+
const tables = Array.isArray(params.tables) ? params.tables : params.tables ? [params.tables] : [];
|
|
152
|
+
const tableNames = tables.map((table) => is(table, Table) ? table[OriginalName] : table);
|
|
153
|
+
const compositeTableSets = tableNames.map((table) => this.addTablePrefix(table));
|
|
154
|
+
await this.luaScripts.onMutateScript.exec([UpstashCache.tagsMapKey, ...compositeTableSets], tags);
|
|
155
|
+
}
|
|
156
|
+
addTablePrefix = (table) => `${UpstashCache.compositeTableSetPrefix}${table}`;
|
|
157
|
+
getCompositeKey = (tables) => `${UpstashCache.compositeTablePrefix}${tables.sort().join(",")}`;
|
|
158
|
+
}
|
|
159
|
+
function upstashCache({ url, token, config, global = false }) {
|
|
160
|
+
const redis = new Redis({
|
|
161
|
+
url,
|
|
162
|
+
token
|
|
163
|
+
});
|
|
164
|
+
return new UpstashCache(redis, config, global);
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
UpstashCache,
|
|
168
|
+
upstashCache
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/cache/upstash/cache.ts"],"sourcesContent":["import { Redis } from '@upstash/redis';\nimport type { MutationOption } from '~/cache/core/index.ts';\nimport { Cache } from '~/cache/core/index.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { OriginalName, Table } from '~/index.ts';\nimport type { CacheConfig } from '../core/types.ts';\n\nconst getByTagScript = `\nlocal tagsMapKey = KEYS[1] -- tags map key\nlocal tag = ARGV[1] -- tag\n\nlocal compositeTableName = redis.call('HGET', tagsMapKey, tag)\nif not compositeTableName then\n return nil\nend\n\nlocal value = redis.call('HGET', compositeTableName, tag)\nreturn value\n`;\n\nconst onMutateScript = `\nlocal tagsMapKey = KEYS[1] -- tags map key\nlocal tables = {} -- initialize tables array\nlocal tags = ARGV -- tags array\n\nfor i = 2, #KEYS do\n tables[#tables + 1] = KEYS[i] -- add all keys except the first one to tables\nend\n\nif #tags > 0 then\n for _, tag in ipairs(tags) do\n if tag ~= nil and tag ~= '' then\n local compositeTableName = redis.call('HGET', tagsMapKey, tag)\n if compositeTableName then\n redis.call('HDEL', compositeTableName, tag)\n end\n end\n end\n redis.call('HDEL', tagsMapKey, unpack(tags))\nend\n\nlocal keysToDelete = {}\n\nif #tables > 0 then\n local compositeTableNames = redis.call('SUNION', unpack(tables))\n for _, compositeTableName in ipairs(compositeTableNames) do\n keysToDelete[#keysToDelete + 1] = compositeTableName\n end\n for _, table in ipairs(tables) do\n keysToDelete[#keysToDelete + 1] = table\n end\n redis.call('DEL', unpack(keysToDelete))\nend\n`;\n\ntype Script = ReturnType<Redis['createScript']>;\n\ntype ExpireOptions = 'NX' | 'nx' | 'XX' | 'xx' | 'GT' | 'gt' | 'LT' | 'lt';\n\nexport class UpstashCache extends Cache {\n\tstatic override readonly [entityKind]: string = 'UpstashCache';\n\t/**\n\t * Prefix for sets which denote the composite table names for each unique table\n\t *\n\t * Example: In the composite table set of \"table1\", you may find\n\t * `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`\n\t */\n\tprivate static compositeTableSetPrefix = '__CTS__';\n\t/**\n\t * Prefix for hashes which map hash or tags to cache values\n\t */\n\tprivate static compositeTablePrefix = '__CT__';\n\t/**\n\t * Key which holds the mapping of tags to composite table names\n\t *\n\t * Using this tagsMapKey, you can find the composite table name for a given tag\n\t * and get the cache value for that tag:\n\t *\n\t * ```ts\n\t * const compositeTable = redis.hget(tagsMapKey, 'tag1')\n\t * console.log(compositeTable) // `${compositeTablePrefix}table1,table2`\n\t *\n\t * const cachevalue = redis.hget(compositeTable, 'tag1')\n\t */\n\tprivate static tagsMapKey = '__tagsMap__';\n\t/**\n\t * Queries whose auto invalidation is false aren't stored in their respective\n\t * composite table hashes because those hashes are deleted when a mutation\n\t * occurs on related tables.\n\t *\n\t * Instead, they are stored in a separate hash with the prefix\n\t * `__nonAutoInvalidate__` to prevent them from being deleted when a mutation\n\t */\n\tprivate static nonAutoInvalidateTablePrefix = '__nonAutoInvalidate__';\n\n\tprivate luaScripts: {\n\t\tgetByTagScript: Script;\n\t\tonMutateScript: Script;\n\t};\n\n\tprivate internalConfig: { seconds: number; hexOptions?: ExpireOptions };\n\n\tconstructor(public redis: Redis, config?: CacheConfig, protected useGlobally?: boolean) {\n\t\tsuper();\n\t\tthis.internalConfig = this.toInternalConfig(config);\n\t\tthis.luaScripts = {\n\t\t\tgetByTagScript: this.redis.createScript(getByTagScript, { readonly: true }),\n\t\t\tonMutateScript: this.redis.createScript(onMutateScript),\n\t\t};\n\t}\n\n\tpublic strategy() {\n\t\treturn this.useGlobally ? 'all' : 'explicit';\n\t}\n\n\tprivate toInternalConfig(config?: CacheConfig): { seconds: number; hexOptions?: ExpireOptions } {\n\t\treturn config\n\t\t\t? {\n\t\t\t\tseconds: config.ex!,\n\t\t\t\thexOptions: config.hexOptions,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tseconds: 1,\n\t\t\t};\n\t}\n\n\toverride async get(\n\t\tkey: string,\n\t\ttables: string[],\n\t\tisTag: boolean = false,\n\t\tisAutoInvalidate?: boolean,\n\t): Promise<any[] | undefined> {\n\t\tif (!isAutoInvalidate) {\n\t\t\tconst result = await this.redis.hget(UpstashCache.nonAutoInvalidateTablePrefix, key);\n\t\t\treturn result === null ? undefined : result as any[];\n\t\t}\n\n\t\tif (isTag) {\n\t\t\tconst result = await this.luaScripts.getByTagScript.exec([UpstashCache.tagsMapKey], [key]);\n\t\t\treturn result === null ? undefined : result as any[];\n\t\t}\n\n\t\t// Normal cache lookup for the composite key\n\t\tconst compositeKey = this.getCompositeKey(tables);\n\t\tconst result = await this.redis.hget(compositeKey, key) ?? undefined; // Retrieve result for normal query\n\t\treturn result === null ? undefined : result as any[];\n\t}\n\n\toverride async put(\n\t\tkey: string,\n\t\tresponse: any,\n\t\ttables: string[],\n\t\tisTag: boolean = false,\n\t\tconfig?: CacheConfig,\n\t): Promise<void> {\n\t\tconst isAutoInvalidate = tables.length !== 0;\n\n\t\tconst pipeline = this.redis.pipeline();\n\t\tconst ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;\n\t\tconst hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;\n\n\t\tif (!isAutoInvalidate) {\n\t\t\tif (isTag) {\n\t\t\t\tpipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });\n\t\t\t\tpipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);\n\t\t\t}\n\n\t\t\tpipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });\n\t\t\tpipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);\n\t\t\tawait pipeline.exec();\n\t\t\treturn;\n\t\t}\n\n\t\tconst compositeKey = this.getCompositeKey(tables);\n\n\t\tpipeline.hset(compositeKey, { [key]: response }); // Store the result with the tag under the composite key\n\t\tpipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions); // Set expiration for the composite key\n\n\t\tif (isTag) {\n\t\t\tpipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey }); // Store the tag and its composite key in the map\n\t\t\tpipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions); // Set expiration for the tag\n\t\t}\n\n\t\tfor (const table of tables) {\n\t\t\tpipeline.sadd(this.addTablePrefix(table), compositeKey);\n\t\t}\n\n\t\tawait pipeline.exec();\n\t}\n\n\toverride async onMutate(params: MutationOption) {\n\t\tconst tags = Array.isArray(params.tags) ? params.tags : params.tags ? [params.tags] : [];\n\t\tconst tables = Array.isArray(params.tables) ? params.tables : params.tables ? [params.tables] : [];\n\t\tconst tableNames: string[] = tables.map((table) => is(table, Table) ? table[OriginalName] : table as string);\n\n\t\tconst compositeTableSets = tableNames.map((table) => this.addTablePrefix(table));\n\t\tawait this.luaScripts.onMutateScript.exec([UpstashCache.tagsMapKey, ...compositeTableSets], tags);\n\t}\n\n\tprivate addTablePrefix = (table: string) => `${UpstashCache.compositeTableSetPrefix}${table}`;\n\tprivate getCompositeKey = (tables: string[]) => `${UpstashCache.compositeTablePrefix}${tables.sort().join(',')}`;\n}\n\nexport function upstashCache(\n\t{ url, token, config, global = false }: { url: string; token: string; config?: CacheConfig; global?: boolean },\n): UpstashCache {\n\tconst redis = new Redis({\n\t\turl,\n\t\ttoken,\n\t});\n\n\treturn new UpstashCache(redis, config, global);\n}\n"],"mappings":"AAAA,SAAS,aAAa;AA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
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var upstash_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(upstash_exports);
|
|
18
|
+
__reExport(upstash_exports, require("./cache.cjs"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./cache.cjs")
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/cache/upstash/index.ts"],"sourcesContent":["export * from './cache.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,uBAAd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cache.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cache.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/cache/upstash/index.ts"],"sourcesContent":["export * from './cache.ts';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
package/casing.cjs
CHANGED
|
@@ -49,8 +49,7 @@ class CasingCache {
|
|
|
49
49
|
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
50
50
|
}
|
|
51
51
|
getColumnCasing(column) {
|
|
52
|
-
if (!column.keyAsName)
|
|
53
|
-
return column.name;
|
|
52
|
+
if (!column.keyAsName) return column.name;
|
|
54
53
|
const schema = column.table[import_table.Table.Symbol.Schema] ?? "public";
|
|
55
54
|
const tableName = column.table[import_table.Table.Symbol.OriginalName];
|
|
56
55
|
const key = `${schema}.${tableName}.${column.name}`;
|
package/casing.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Column } from '~/column.ts';\nimport { entityKind } from './entity.ts';\nimport { Table } from './table.ts';\nimport type { Casing } from './utils.ts';\n\nexport function toSnakeCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.map((word) => word.toLowerCase()).join('_');\n}\n\nexport function toCamelCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.reduce((acc, word, i) => {\n\t\tconst formattedWord = i === 0 ? word.toLowerCase() : `${word[0]!.toUpperCase()}${word.slice(1)}`;\n\t\treturn acc + formattedWord;\n\t}, '');\n}\n\nfunction noopCase(input: string) {\n\treturn input;\n}\n\nexport class CasingCache {\n\tstatic readonly [entityKind]: string = 'CasingCache';\n\n\t/** @internal */\n\tcache: Record<string, string> = {};\n\tprivate cachedTables: Record<string, true> = {};\n\tprivate convert: (input: string) => string;\n\n\tconstructor(casing?: Casing) {\n\t\tthis.convert = casing === 'snake_case'\n\t\t\t? toSnakeCase\n\t\t\t: casing === 'camelCase'\n\t\t\t? toCamelCase\n\t\t\t: noopCase;\n\t}\n\n\tgetColumnCasing(column: Column): string {\n\t\tif (!column.keyAsName) return column.name;\n\n\t\tconst schema = column.table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = column.table[Table.Symbol.OriginalName];\n\t\tconst key = `${schema}.${tableName}.${column.name}`;\n\n\t\tif (!this.cache[key]) {\n\t\t\tthis.cacheTable(column.table);\n\t\t}\n\t\treturn this.cache[key]!;\n\t}\n\n\tprivate cacheTable(table: Table) {\n\t\tconst schema = table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = table[Table.Symbol.OriginalName];\n\t\tconst tableKey = `${schema}.${tableName}`;\n\n\t\tif (!this.cachedTables[tableKey]) {\n\t\t\tfor (const column of Object.values(table[Table.Symbol.Columns])) {\n\t\t\t\tconst columnKey = `${tableKey}.${column.name}`;\n\t\t\t\tthis.cache[columnKey] = this.convert(column.name);\n\t\t\t}\n\t\t\tthis.cachedTables[tableKey] = true;\n\t\t}\n\t}\n\n\tclearCache() {\n\t\tthis.cache = {};\n\t\tthis.cachedTables = {};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAC3B,mBAAsB;AAGf,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,IAAI,CAAC,SAAS,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACxD;AAEO,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM;AACrC,UAAM,gBAAgB,MAAM,IAAI,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,EAAG,YAAY,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;AAC9F,WAAO,MAAM;AAAA,EACd,GAAG,EAAE;AACN;AAEA,SAAS,SAAS,OAAe;AAChC,SAAO;AACR;AAEO,MAAM,YAAY;AAAA,EACxB,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC,QAAgC,CAAC;AAAA,EACzB,eAAqC,CAAC;AAAA,EACtC;AAAA,EAER,YAAY,QAAiB;AAC5B,SAAK,UAAU,WAAW,eACvB,cACA,WAAW,cACX,cACA;AAAA,EACJ;AAAA,EAEA,gBAAgB,QAAwB;AACvC,QAAI,CAAC,OAAO
|
|
1
|
+
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Column } from '~/column.ts';\nimport { entityKind } from './entity.ts';\nimport { Table } from './table.ts';\nimport type { Casing } from './utils.ts';\n\nexport function toSnakeCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.map((word) => word.toLowerCase()).join('_');\n}\n\nexport function toCamelCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.reduce((acc, word, i) => {\n\t\tconst formattedWord = i === 0 ? word.toLowerCase() : `${word[0]!.toUpperCase()}${word.slice(1)}`;\n\t\treturn acc + formattedWord;\n\t}, '');\n}\n\nfunction noopCase(input: string) {\n\treturn input;\n}\n\nexport class CasingCache {\n\tstatic readonly [entityKind]: string = 'CasingCache';\n\n\t/** @internal */\n\tcache: Record<string, string> = {};\n\tprivate cachedTables: Record<string, true> = {};\n\tprivate convert: (input: string) => string;\n\n\tconstructor(casing?: Casing) {\n\t\tthis.convert = casing === 'snake_case'\n\t\t\t? toSnakeCase\n\t\t\t: casing === 'camelCase'\n\t\t\t? toCamelCase\n\t\t\t: noopCase;\n\t}\n\n\tgetColumnCasing(column: Column): string {\n\t\tif (!column.keyAsName) return column.name;\n\n\t\tconst schema = column.table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = column.table[Table.Symbol.OriginalName];\n\t\tconst key = `${schema}.${tableName}.${column.name}`;\n\n\t\tif (!this.cache[key]) {\n\t\t\tthis.cacheTable(column.table);\n\t\t}\n\t\treturn this.cache[key]!;\n\t}\n\n\tprivate cacheTable(table: Table) {\n\t\tconst schema = table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = table[Table.Symbol.OriginalName];\n\t\tconst tableKey = `${schema}.${tableName}`;\n\n\t\tif (!this.cachedTables[tableKey]) {\n\t\t\tfor (const column of Object.values(table[Table.Symbol.Columns])) {\n\t\t\t\tconst columnKey = `${tableKey}.${column.name}`;\n\t\t\t\tthis.cache[columnKey] = this.convert(column.name);\n\t\t\t}\n\t\t\tthis.cachedTables[tableKey] = true;\n\t\t}\n\t}\n\n\tclearCache() {\n\t\tthis.cache = {};\n\t\tthis.cachedTables = {};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAC3B,mBAAsB;AAGf,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,IAAI,CAAC,SAAS,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACxD;AAEO,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM;AACrC,UAAM,gBAAgB,MAAM,IAAI,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,EAAG,YAAY,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;AAC9F,WAAO,MAAM;AAAA,EACd,GAAG,EAAE;AACN;AAEA,SAAS,SAAS,OAAe;AAChC,SAAO;AACR;AAEO,MAAM,YAAY;AAAA,EACxB,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC,QAAgC,CAAC;AAAA,EACzB,eAAqC,CAAC;AAAA,EACtC;AAAA,EAER,YAAY,QAAiB;AAC5B,SAAK,UAAU,WAAW,eACvB,cACA,WAAW,cACX,cACA;AAAA,EACJ;AAAA,EAEA,gBAAgB,QAAwB;AACvC,QAAI,CAAC,OAAO,UAAW,QAAO,OAAO;AAErC,UAAM,SAAS,OAAO,MAAM,mBAAM,OAAO,MAAM,KAAK;AACpD,UAAM,YAAY,OAAO,MAAM,mBAAM,OAAO,YAAY;AACxD,UAAM,MAAM,GAAG,MAAM,IAAI,SAAS,IAAI,OAAO,IAAI;AAEjD,QAAI,CAAC,KAAK,MAAM,GAAG,GAAG;AACrB,WAAK,WAAW,OAAO,KAAK;AAAA,IAC7B;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACtB;AAAA,EAEQ,WAAW,OAAc;AAChC,UAAM,SAAS,MAAM,mBAAM,OAAO,MAAM,KAAK;AAC7C,UAAM,YAAY,MAAM,mBAAM,OAAO,YAAY;AACjD,UAAM,WAAW,GAAG,MAAM,IAAI,SAAS;AAEvC,QAAI,CAAC,KAAK,aAAa,QAAQ,GAAG;AACjC,iBAAW,UAAU,OAAO,OAAO,MAAM,mBAAM,OAAO,OAAO,CAAC,GAAG;AAChE,cAAM,YAAY,GAAG,QAAQ,IAAI,OAAO,IAAI;AAC5C,aAAK,MAAM,SAAS,IAAI,KAAK,QAAQ,OAAO,IAAI;AAAA,MACjD;AACA,WAAK,aAAa,QAAQ,IAAI;AAAA,IAC/B;AAAA,EACD;AAAA,EAEA,aAAa;AACZ,SAAK,QAAQ,CAAC;AACd,SAAK,eAAe,CAAC;AAAA,EACtB;AACD;","names":[]}
|
package/casing.js
CHANGED
|
@@ -24,8 +24,7 @@ class CasingCache {
|
|
|
24
24
|
this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase;
|
|
25
25
|
}
|
|
26
26
|
getColumnCasing(column) {
|
|
27
|
-
if (!column.keyAsName)
|
|
28
|
-
return column.name;
|
|
27
|
+
if (!column.keyAsName) return column.name;
|
|
29
28
|
const schema = column.table[Table.Symbol.Schema] ?? "public";
|
|
30
29
|
const tableName = column.table[Table.Symbol.OriginalName];
|
|
31
30
|
const key = `${schema}.${tableName}.${column.name}`;
|
package/casing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Column } from '~/column.ts';\nimport { entityKind } from './entity.ts';\nimport { Table } from './table.ts';\nimport type { Casing } from './utils.ts';\n\nexport function toSnakeCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.map((word) => word.toLowerCase()).join('_');\n}\n\nexport function toCamelCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.reduce((acc, word, i) => {\n\t\tconst formattedWord = i === 0 ? word.toLowerCase() : `${word[0]!.toUpperCase()}${word.slice(1)}`;\n\t\treturn acc + formattedWord;\n\t}, '');\n}\n\nfunction noopCase(input: string) {\n\treturn input;\n}\n\nexport class CasingCache {\n\tstatic readonly [entityKind]: string = 'CasingCache';\n\n\t/** @internal */\n\tcache: Record<string, string> = {};\n\tprivate cachedTables: Record<string, true> = {};\n\tprivate convert: (input: string) => string;\n\n\tconstructor(casing?: Casing) {\n\t\tthis.convert = casing === 'snake_case'\n\t\t\t? toSnakeCase\n\t\t\t: casing === 'camelCase'\n\t\t\t? toCamelCase\n\t\t\t: noopCase;\n\t}\n\n\tgetColumnCasing(column: Column): string {\n\t\tif (!column.keyAsName) return column.name;\n\n\t\tconst schema = column.table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = column.table[Table.Symbol.OriginalName];\n\t\tconst key = `${schema}.${tableName}.${column.name}`;\n\n\t\tif (!this.cache[key]) {\n\t\t\tthis.cacheTable(column.table);\n\t\t}\n\t\treturn this.cache[key]!;\n\t}\n\n\tprivate cacheTable(table: Table) {\n\t\tconst schema = table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = table[Table.Symbol.OriginalName];\n\t\tconst tableKey = `${schema}.${tableName}`;\n\n\t\tif (!this.cachedTables[tableKey]) {\n\t\t\tfor (const column of Object.values(table[Table.Symbol.Columns])) {\n\t\t\t\tconst columnKey = `${tableKey}.${column.name}`;\n\t\t\t\tthis.cache[columnKey] = this.convert(column.name);\n\t\t\t}\n\t\t\tthis.cachedTables[tableKey] = true;\n\t\t}\n\t}\n\n\tclearCache() {\n\t\tthis.cache = {};\n\t\tthis.cachedTables = {};\n\t}\n}\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAGf,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,IAAI,CAAC,SAAS,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACxD;AAEO,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM;AACrC,UAAM,gBAAgB,MAAM,IAAI,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,EAAG,YAAY,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;AAC9F,WAAO,MAAM;AAAA,EACd,GAAG,EAAE;AACN;AAEA,SAAS,SAAS,OAAe;AAChC,SAAO;AACR;AAEO,MAAM,YAAY;AAAA,EACxB,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC,QAAgC,CAAC;AAAA,EACzB,eAAqC,CAAC;AAAA,EACtC;AAAA,EAER,YAAY,QAAiB;AAC5B,SAAK,UAAU,WAAW,eACvB,cACA,WAAW,cACX,cACA;AAAA,EACJ;AAAA,EAEA,gBAAgB,QAAwB;AACvC,QAAI,CAAC,OAAO
|
|
1
|
+
{"version":3,"sources":["../src/casing.ts"],"sourcesContent":["import type { Column } from '~/column.ts';\nimport { entityKind } from './entity.ts';\nimport { Table } from './table.ts';\nimport type { Casing } from './utils.ts';\n\nexport function toSnakeCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.map((word) => word.toLowerCase()).join('_');\n}\n\nexport function toCamelCase(input: string) {\n\tconst words = input\n\t\t.replace(/['\\u2019]/g, '')\n\t\t.match(/[\\da-z]+|[A-Z]+(?![a-z])|[A-Z][\\da-z]+/g) ?? [];\n\n\treturn words.reduce((acc, word, i) => {\n\t\tconst formattedWord = i === 0 ? word.toLowerCase() : `${word[0]!.toUpperCase()}${word.slice(1)}`;\n\t\treturn acc + formattedWord;\n\t}, '');\n}\n\nfunction noopCase(input: string) {\n\treturn input;\n}\n\nexport class CasingCache {\n\tstatic readonly [entityKind]: string = 'CasingCache';\n\n\t/** @internal */\n\tcache: Record<string, string> = {};\n\tprivate cachedTables: Record<string, true> = {};\n\tprivate convert: (input: string) => string;\n\n\tconstructor(casing?: Casing) {\n\t\tthis.convert = casing === 'snake_case'\n\t\t\t? toSnakeCase\n\t\t\t: casing === 'camelCase'\n\t\t\t? toCamelCase\n\t\t\t: noopCase;\n\t}\n\n\tgetColumnCasing(column: Column): string {\n\t\tif (!column.keyAsName) return column.name;\n\n\t\tconst schema = column.table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = column.table[Table.Symbol.OriginalName];\n\t\tconst key = `${schema}.${tableName}.${column.name}`;\n\n\t\tif (!this.cache[key]) {\n\t\t\tthis.cacheTable(column.table);\n\t\t}\n\t\treturn this.cache[key]!;\n\t}\n\n\tprivate cacheTable(table: Table) {\n\t\tconst schema = table[Table.Symbol.Schema] ?? 'public';\n\t\tconst tableName = table[Table.Symbol.OriginalName];\n\t\tconst tableKey = `${schema}.${tableName}`;\n\n\t\tif (!this.cachedTables[tableKey]) {\n\t\t\tfor (const column of Object.values(table[Table.Symbol.Columns])) {\n\t\t\t\tconst columnKey = `${tableKey}.${column.name}`;\n\t\t\t\tthis.cache[columnKey] = this.convert(column.name);\n\t\t\t}\n\t\t\tthis.cachedTables[tableKey] = true;\n\t\t}\n\t}\n\n\tclearCache() {\n\t\tthis.cache = {};\n\t\tthis.cachedTables = {};\n\t}\n}\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAGf,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,IAAI,CAAC,SAAS,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACxD;AAEO,SAAS,YAAY,OAAe;AAC1C,QAAM,QAAQ,MACZ,QAAQ,cAAc,EAAE,EACxB,MAAM,yCAAyC,KAAK,CAAC;AAEvD,SAAO,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM;AACrC,UAAM,gBAAgB,MAAM,IAAI,KAAK,YAAY,IAAI,GAAG,KAAK,CAAC,EAAG,YAAY,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;AAC9F,WAAO,MAAM;AAAA,EACd,GAAG,EAAE;AACN;AAEA,SAAS,SAAS,OAAe;AAChC,SAAO;AACR;AAEO,MAAM,YAAY;AAAA,EACxB,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC,QAAgC,CAAC;AAAA,EACzB,eAAqC,CAAC;AAAA,EACtC;AAAA,EAER,YAAY,QAAiB;AAC5B,SAAK,UAAU,WAAW,eACvB,cACA,WAAW,cACX,cACA;AAAA,EACJ;AAAA,EAEA,gBAAgB,QAAwB;AACvC,QAAI,CAAC,OAAO,UAAW,QAAO,OAAO;AAErC,UAAM,SAAS,OAAO,MAAM,MAAM,OAAO,MAAM,KAAK;AACpD,UAAM,YAAY,OAAO,MAAM,MAAM,OAAO,YAAY;AACxD,UAAM,MAAM,GAAG,MAAM,IAAI,SAAS,IAAI,OAAO,IAAI;AAEjD,QAAI,CAAC,KAAK,MAAM,GAAG,GAAG;AACrB,WAAK,WAAW,OAAO,KAAK;AAAA,IAC7B;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACtB;AAAA,EAEQ,WAAW,OAAc;AAChC,UAAM,SAAS,MAAM,MAAM,OAAO,MAAM,KAAK;AAC7C,UAAM,YAAY,MAAM,MAAM,OAAO,YAAY;AACjD,UAAM,WAAW,GAAG,MAAM,IAAI,SAAS;AAEvC,QAAI,CAAC,KAAK,aAAa,QAAQ,GAAG;AACjC,iBAAW,UAAU,OAAO,OAAO,MAAM,MAAM,OAAO,OAAO,CAAC,GAAG;AAChE,cAAM,YAAY,GAAG,QAAQ,IAAI,OAAO,IAAI;AAC5C,aAAK,MAAM,SAAS,IAAI,KAAK,QAAQ,OAAO,IAAI;AAAA,MACjD;AACA,WAAK,aAAa,QAAQ,IAAI;AAAA,IAC/B;AAAA,EACD;AAAA,EAEA,aAAa;AACZ,SAAK,QAAQ,CAAC;AACd,SAAK,eAAe,CAAC;AAAA,EACtB;AACD;","names":[]}
|
package/column-builder.cjs
CHANGED
|
@@ -119,8 +119,7 @@ class ColumnBuilder {
|
|
|
119
119
|
}
|
|
120
120
|
/** @internal Sets the name of the column to the key within the table definition if a name was not given. */
|
|
121
121
|
setName(name) {
|
|
122
|
-
if (this.config.name !== "")
|
|
123
|
-
return;
|
|
122
|
+
if (this.config.name !== "") return;
|
|
124
123
|
this.config.name = name;
|
|
125
124
|
}
|
|
126
125
|
}
|