New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lbu/store

Package Overview
Dependencies
Maintainers
2
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lbu/store - npm Package Compare versions

Comparing version 0.0.75 to 0.0.76

78

index.d.ts

@@ -84,3 +84,3 @@ import * as minioVendor from "minio";

opts?: postgresVendor.Options<{}> & { createIfNotExists?: boolean },
): Promise<postgresVendor.Sql<{}>>;
): Promise<Postgres>;

@@ -107,3 +107,3 @@ /**

verboseSql?: boolean,
): Promise<postgresVendor.Sql<{}>>;
): Promise<Postgres>;

@@ -113,5 +113,3 @@ /**

*/
export function cleanupTestPostgresDatabase(
sql: postgresVendor.Sql<{}>,
): Promise<void>;
export function cleanupTestPostgresDatabase(sql: Postgres): Promise<void>;

@@ -139,3 +137,3 @@ /**

storedHashes: Record<string, string>;
sql: postgresVendor.Sql<{}>;
sql: Postgres;
}

@@ -147,5 +145,3 @@

*/
export function newMigrationContext(
sql: postgresVendor.Sql<{}>,
): Promise<MigrateContext>;
export function newMigrationContext(sql: Postgres): Promise<MigrateContext>;

@@ -165,17 +161,2 @@ /**

export interface FileStoreContext {
sql: postgresVendor.Sql<{}>;
minio: minioVendor.Client;
bucketName: string;
}
/**
* Create a new FileStoreContext
*/
export function newFileStoreContext(
sql: postgresVendor.Sql<{}>,
minio: minioVendor.Client,
bucketName: string,
): FileStoreContext;
export interface StoreFileStore {

@@ -197,3 +178,5 @@ id: string;

export function createOrUpdateFile(
fc: FileStoreContext,
sql: Postgres,
minio: minioVendor.Client,
bucketName: string,
props: {

@@ -212,11 +195,9 @@ id?: string;

/**
* Delete a file by id
* Does not remove the object from minio bucket
*/
export function deleteFile(fc: FileStoreContext, id: string): Promise<void>;
/**
* Sync deleted files to the minio bucket
*/
export function syncDeletedFiles(fc: FileStoreContext);
export function syncDeletedFiles(
sql: Postgres,
minio: minioVendor.Client,
bucketName: string,
);

@@ -227,3 +208,5 @@ /**

export function copyFile(
fc: FileStoreContext,
sql: Postgres,
minio: minioVendor.Client,
bucketName: string,
id: string,

@@ -234,14 +217,7 @@ targetBucket?: string,

/**
* Select a file by id
*/
export function getFileById(
fc: FileStoreContext,
id: string,
): Promise<StoreFileStore | undefined>;
/**
* Open a ReadStream for a (partial) file
*/
export function getFileStream(
fc: FileStoreContext,
minio: minioVendor.Client,
bucketName: string,
id: string,

@@ -276,3 +252,8 @@ range?: { start?: number; end?: number },

constructor(fileStore: FileStoreContext, options?: FileCacheOptions);
constructor(
sql: Postgres,
minio: minioVendor.Client,
bucketName: string,
options?: FileCacheOptions,
);

@@ -331,3 +312,3 @@ /**

export interface JobQueueWorkerOptions {
handler: (sql: postgresVendor.Sql<{}>, data: JobData) => void | Promise<void>;
handler: (sql: Postgres, data: JobData) => void | Promise<void>;

@@ -352,3 +333,3 @@ /**

constructor(
sql: postgresVendor.Sql<{}>,
sql: Postgres,
nameOrOptions: string | JobQueueWorkerOptions,

@@ -393,6 +374,3 @@ options?: JobQueueWorkerOptions,

*/
export function addJobToQueue(
sql: postgresVendor.Sql<{}>,
job: JobInput,
): Promise<number>;
export function addJobToQueue(sql: Postgres, job: JobInput): Promise<number>;

@@ -418,3 +396,3 @@ /**

*/
export function newSessionStore(sql: postgresVendor.Sql<{}>): SessionStore;
export function newSessionStore(sql: Postgres): SessionStore;

@@ -421,0 +399,0 @@ /**

@@ -31,6 +31,3 @@ import { dirnameForModule } from "@lbu/stdlib";

copyFile,
getFileById,
getFileStream,
newFileStoreContext,
deleteFile,
syncDeletedFiles,

@@ -37,0 +34,0 @@ } from "./src/files.js";

{
"name": "@lbu/store",
"version": "0.0.75",
"version": "0.0.76",
"description": "Postgres & S3-compatible wrappers for common things",

@@ -18,4 +18,4 @@ "main": "./index.js",

"dependencies": {
"@lbu/insight": "0.0.75",
"@lbu/stdlib": "0.0.75",
"@lbu/insight": "0.0.76",
"@lbu/stdlib": "0.0.76",
"@types/minio": "7.0.6",

@@ -47,3 +47,3 @@ "mime-types": "2.1.27",

},
"gitHead": "b89ec55fceee61902fe1ee79e4c658ff70f0b129"
"gitHead": "4d5245ee1c104c3fb11e37afd6a9a226fa29706c"
}
import { once } from "events";
import { createReadStream, createWriteStream } from "fs";
import { mkdirSync, createReadStream, createWriteStream } from "fs";
import { pipeline as pipelineCallbacks, Readable } from "stream";
import { promisify } from "util";
import { isNil, pathJoin } from "@lbu/stdlib";
import { isNil, pathJoin, uuid } from "@lbu/stdlib";
import { getFileStream } from "./files.js";

@@ -11,10 +11,14 @@

export class FileCache {
static fileCachePath = "/tmp";
static fileCachePath = `/tmp/lbu-cache/${uuid()}/`;
/**
* @param {FileStoreContext} fileStore
* @param {Postgres} sql
* @param {minio.Client} minio
* @param {string} bucketName
* @param {FileCacheOptions} [options]
*/
constructor(fileStore, options) {
this.fileStore = fileStore;
constructor(sql, minio, bucketName, options) {
this.sql = sql;
this.minio = minio;
this.bucketName = bucketName;

@@ -33,2 +37,6 @@ this.inMemoryThreshold = options?.inMemoryThreshold ?? 8 * 1024;

this.getStreamFn = this.getFileStream.bind(this);
// Create the directory synchronously
// So we don't have to track if it was made or not
mkdirSync(FileCache.fileCachePath, { recursive: true });
}

@@ -124,10 +132,11 @@

const buffers = [];
await pipeline(await getFileStream(this.fileStore, id), async function* (
transform,
) {
for await (const chunk of transform) {
buffers.push(chunk);
yield chunk;
}
});
await pipeline(
await getFileStream(this.minio, this.bucketName, id),
async function* (transform) {
for await (const chunk of transform) {
buffers.push(chunk);
yield chunk;
}
},
);

@@ -153,3 +162,3 @@ this.memoryCache.set(key, Buffer.concat(buffers));

await pipeline(
await getFileStream(this.fileStore, id),
await getFileStream(this.minio, this.bucketName, id),
createWriteStream(pathJoin(FileCache.fileCachePath, key)),

@@ -156,0 +165,0 @@ );

@@ -21,16 +21,5 @@ import { createReadStream } from "fs";

/**
* @param sql
* @param {Postgres} sql
* @param {minio.Client} minio
* @param {string} bucketName
*/
export function newFileStoreContext(sql, minio, bucketName) {
return {
sql,
minio,
bucketName,
};
}
/**
* @param {FileStoreContext} fc
* @param {StoreFileStoreInsertPartial_Input & { id?: string }} props

@@ -40,3 +29,9 @@ * @param {ReadStream|string} streamOrPath

*/
export async function createOrUpdateFile(fc, props, streamOrPath) {
export async function createOrUpdateFile(
sql,
minio,
bucketName,
props,
streamOrPath,
) {
if (!props.filename) {

@@ -50,3 +45,3 @@ throw new Error("filename is required on file props");

props.bucketName = fc.bucketName;
props.bucketName = bucketName;

@@ -56,3 +51,3 @@ // Do a manual insert first to get an id

props.contentLength = 0;
const [intermediate] = await storeQueries.fileStoreInsert(fc.sql, props);
const [intermediate] = await storeQueries.fileStoreInsert(sql, props);
props.id = intermediate.id;

@@ -65,9 +60,9 @@ }

await fc.minio.putObject(fc.bucketName, props.id, streamOrPath, {
await minio.putObject(bucketName, props.id, streamOrPath, {
"content-type": props.contentType,
});
const stat = await fc.minio.statObject(fc.bucketName, props.id);
const stat = await minio.statObject(bucketName, props.id);
props.contentLength = stat.size;
const [result] = await storeQueries.fileStoreUpdate(fc.sql, props, {
const [result] = await storeQueries.fileStoreUpdate(sql, props, {
id: props.id,

@@ -80,18 +75,5 @@ });

/**
* @param {FileStoreContext} fc
* @param {minio.Client} minio
* @param {string} bucketName
* @param {string} id
* @returns {Promise<StoreFileStore|undefined>}
*/
export async function getFileById(fc, id) {
const [result] = await storeQueries.fileStoreSelect(fc.sql, {
id,
bucketName: fc.bucketName,
});
return result;
}
/**
* @param {FileStoreContext} fc
* @param {string} id
* @param {number} [start]

@@ -101,3 +83,8 @@ * @param {number} [end]

*/
export async function getFileStream(fc, id, { start, end } = {}) {
export async function getFileStream(
minio,
bucketName,
id,
{ start, end } = {},
) {
if (start !== undefined || end !== undefined) {

@@ -107,29 +94,33 @@ start = start || 0;

return fc.minio.getPartialObject(fc.bucketName, id, start, size);
return minio.getPartialObject(bucketName, id, start, size);
}
return fc.minio.getObject(fc.bucketName, id);
return minio.getObject(bucketName, id);
}
/**
* @param {FileStoreContext} fc
* @param {Postgres} sql
* @param {minio.Client} minio
* @param {string} bucketName
* @param {string} id
* @param {string} [targetBucket=fc.bucketName]
* @param {string} [targetBucket=bucketName]
* @returns {Promise<StoreFileStore>}
*/
export async function copyFile(fc, id, targetBucket = fc.bucketName) {
export async function copyFile(
sql,
minio,
bucketName,
id,
targetBucket = bucketName,
) {
const [intermediate] = await queries.copyFile(
fc.sql,
sql,
uuid(),
targetBucket,
id,
fc.bucketName,
bucketName,
);
await fc.minio.copyObject(
targetBucket,
intermediate.id,
`${fc.bucketName}/${id}`,
);
await minio.copyObject(targetBucket, intermediate.id, `${bucketName}/${id}`);
const [result] = await storeQueries.fileStoreSelect(fc.sql, {
const [result] = await storeQueries.fileStoreSelect(sql, {
id: intermediate.id,

@@ -142,21 +133,12 @@ });

/**
* @param fc
* @param id
* @param {Postgres} sql
* @param {minio.Client} minio
* @param {string} bucketName
*/
export async function deleteFile(fc, id) {
return storeQueries.fileStoreDelete(fc.sql, {
id,
bucketName: fc.bucketName,
export async function syncDeletedFiles(sql, minio, bucketName) {
const minioObjectsPromise = listObjects(minio, bucketName);
const knownIds = await storeQueries.fileStoreSelect(sql, {
bucketName: bucketName,
});
}
/**
* @param fc
*/
export async function syncDeletedFiles(fc) {
const minioObjectsPromise = listObjects(fc.minio, fc.bucketName);
const knownIds = await storeQueries.fileStoreSelect(fc.sql, {
bucketName: fc.bucketName,
});
const ids = knownIds.map((it) => it.id);

@@ -173,5 +155,5 @@

await fc.minio.removeObjects(fc.bucketName, deletingSet);
await minio.removeObjects(bucketName, deletingSet);
return deletingSet.length;
}

@@ -28,3 +28,25 @@ // Generated by @lbu/code-gen

where?.bucketNameLike ?? null
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`})
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR fs."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR fs."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR fs."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR fs."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR fs."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR fs."updatedAt" < ${where?.updatedAtLowerThan ?? null})
ORDER BY fs."createdAt", fs."updatedAt" , fs."id"

@@ -53,3 +75,25 @@ `,

where?.bucketNameLike ?? null
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`})
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR fs."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR fs."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR fs."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR fs."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR fs."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR fs."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`;

@@ -78,3 +122,25 @@ return parseInt(result?.[0]?.genCount ?? "0");

where?.bucketNameLike ?? null
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`})
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR fs."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR fs."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR fs."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR fs."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR fs."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR fs."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`,

@@ -134,3 +200,25 @@

where?.bucketNameLike ?? null
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`})
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR fs."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR fs."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR fs."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR fs."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR fs."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR fs."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`;

@@ -197,2 +285,38 @@ let query = `UPDATE "fileStore" fs SET `;

}
if (where.createdAt !== undefined) {
query += `fs."createdAt" `;
query += `= $${idx++}`;
argList.push(where.createdAt);
query += " AND ";
}
if (where.createdAtGreaterThan !== undefined) {
query += `fs."createdAt" `;
query += `> $${idx++}`;
argList.push(where.createdAtGreaterThan);
query += " AND ";
}
if (where.createdAtLowerThan !== undefined) {
query += `fs."createdAt" `;
query += `< $${idx++}`;
argList.push(where.createdAtLowerThan);
query += " AND ";
}
if (where.updatedAt !== undefined) {
query += `fs."updatedAt" `;
query += `= $${idx++}`;
argList.push(where.updatedAt);
query += " AND ";
}
if (where.updatedAtGreaterThan !== undefined) {
query += `fs."updatedAt" `;
query += `> $${idx++}`;
argList.push(where.updatedAtGreaterThan);
query += " AND ";
}
if (where.updatedAtLowerThan !== undefined) {
query += `fs."updatedAt" `;
query += `< $${idx++}`;
argList.push(where.updatedAtLowerThan);
query += " AND ";
}
query = query.substring(0, query.length - 4);

@@ -225,3 +349,25 @@ query += ` RETURNING fs."id", fs."bucketName", fs."contentLength", fs."contentType", fs."filename", fs."createdAt", fs."updatedAt"`;

where?.bucketNameLike ?? null
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`})
}, NULL) IS NULL OR fs."bucketName" LIKE ${`%${where?.bucketNameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR fs."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR fs."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR fs."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR fs."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR fs."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR fs."updatedAt" < ${where?.updatedAtLowerThan ?? null})
GROUP BY fs.id

@@ -248,2 +394,14 @@ ORDER BY fs."createdAt", fs."updatedAt" , fs."id"

where?.idLowerThan ?? null
}) AND (COALESCE(${
where?.scheduledAt ?? null
}, NULL) IS NULL OR jq."scheduledAt" = ${
where?.scheduledAt ?? null
}) AND (COALESCE(${
where?.scheduledAtGreaterThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" > ${
where?.scheduledAtGreaterThan ?? null
}) AND (COALESCE(${
where?.scheduledAtLowerThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" < ${
where?.scheduledAtLowerThan ?? null
}) AND (COALESCE(${where?.name ?? null}, NULL) IS NULL OR jq."name" = ${

@@ -253,3 +411,25 @@ where?.name ?? null

where?.nameLike ?? null
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`})
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR jq."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR jq."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR jq."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR jq."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR jq."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR jq."updatedAt" < ${where?.updatedAtLowerThan ?? null})
ORDER BY jq."createdAt", jq."updatedAt" , jq."id"

@@ -276,2 +456,14 @@ `,

where?.idLowerThan ?? null
}) AND (COALESCE(${
where?.scheduledAt ?? null
}, NULL) IS NULL OR jq."scheduledAt" = ${
where?.scheduledAt ?? null
}) AND (COALESCE(${
where?.scheduledAtGreaterThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" > ${
where?.scheduledAtGreaterThan ?? null
}) AND (COALESCE(${
where?.scheduledAtLowerThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" < ${
where?.scheduledAtLowerThan ?? null
}) AND (COALESCE(${where?.name ?? null}, NULL) IS NULL OR jq."name" = ${

@@ -281,3 +473,25 @@ where?.name ?? null

where?.nameLike ?? null
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`})
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR jq."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR jq."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR jq."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR jq."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR jq."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR jq."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`;

@@ -302,2 +516,14 @@ return parseInt(result?.[0]?.genCount ?? "0");

where?.idLowerThan ?? null
}) AND (COALESCE(${
where?.scheduledAt ?? null
}, NULL) IS NULL OR jq."scheduledAt" = ${
where?.scheduledAt ?? null
}) AND (COALESCE(${
where?.scheduledAtGreaterThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" > ${
where?.scheduledAtGreaterThan ?? null
}) AND (COALESCE(${
where?.scheduledAtLowerThan ?? null
}, NULL) IS NULL OR jq."scheduledAt" < ${
where?.scheduledAtLowerThan ?? null
}) AND (COALESCE(${where?.name ?? null}, NULL) IS NULL OR jq."name" = ${

@@ -307,3 +533,25 @@ where?.name ?? null

where?.nameLike ?? null
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`})
}, NULL) IS NULL OR jq."name" LIKE ${`%${where?.nameLike}%`}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR jq."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR jq."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR jq."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR jq."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR jq."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR jq."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`,

@@ -398,2 +646,20 @@

}
if (where.scheduledAt !== undefined) {
query += `jq."scheduledAt" `;
query += `= $${idx++}`;
argList.push(where.scheduledAt);
query += " AND ";
}
if (where.scheduledAtGreaterThan !== undefined) {
query += `jq."scheduledAt" `;
query += `> $${idx++}`;
argList.push(where.scheduledAtGreaterThan);
query += " AND ";
}
if (where.scheduledAtLowerThan !== undefined) {
query += `jq."scheduledAt" `;
query += `< $${idx++}`;
argList.push(where.scheduledAtLowerThan);
query += " AND ";
}
if (where.name !== undefined) {

@@ -411,2 +677,38 @@ query += `jq."name" `;

}
if (where.createdAt !== undefined) {
query += `jq."createdAt" `;
query += `= $${idx++}`;
argList.push(where.createdAt);
query += " AND ";
}
if (where.createdAtGreaterThan !== undefined) {
query += `jq."createdAt" `;
query += `> $${idx++}`;
argList.push(where.createdAtGreaterThan);
query += " AND ";
}
if (where.createdAtLowerThan !== undefined) {
query += `jq."createdAt" `;
query += `< $${idx++}`;
argList.push(where.createdAtLowerThan);
query += " AND ";
}
if (where.updatedAt !== undefined) {
query += `jq."updatedAt" `;
query += `= $${idx++}`;
argList.push(where.updatedAt);
query += " AND ";
}
if (where.updatedAtGreaterThan !== undefined) {
query += `jq."updatedAt" `;
query += `> $${idx++}`;
argList.push(where.updatedAtGreaterThan);
query += " AND ";
}
if (where.updatedAtLowerThan !== undefined) {
query += `jq."updatedAt" `;
query += `< $${idx++}`;
argList.push(where.updatedAtLowerThan);
query += " AND ";
}
query = query.substring(0, query.length - 4);

@@ -439,2 +741,23 @@ query += ` RETURNING jq."id", jq."isComplete", jq."priority", jq."scheduledAt", jq."name", jq."data", jq."createdAt", jq."updatedAt"`;

/**
* Note: Use only when scheduledAt has a unique constraint
* @param sql
* @param { StoreJobQueueInsertPartial_Input & { id?: number } } it
* @returns {Promise<StoreJobQueue[]>}
*/
jobQueueUpsertByScheduledAt: (sql, it) => {
return sql`
INSERT INTO "jobQueue" ("id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
) VALUES (
${it.id ?? uuid()}, ${it.isComplete ?? false}, ${it.priority ?? 0}, ${
it.scheduledAt ?? new Date()
}, ${it.name ?? null}, ${JSON.stringify(it.data ?? {})}, ${
it.createdAt ?? new Date()
}, ${it.updatedAt ?? new Date()}
) ON CONFLICT("scheduledAt") DO UPDATE SET
"isComplete" = EXCLUDED."isComplete", "priority" = EXCLUDED."priority", "name" = EXCLUDED."name", "data" = EXCLUDED."data", "updatedAt" = EXCLUDED."updatedAt"
RETURNING "id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
`;
},
/**
* Note: Use only when name has a unique constraint

@@ -461,3 +784,45 @@ * @param sql

/**
* Note: Use only when createdAt has a unique constraint
* @param sql
* @param { StoreJobQueueInsertPartial_Input & { id?: number } } it
* @returns {Promise<StoreJobQueue[]>}
*/
jobQueueUpsertByCreatedAt: (sql, it) => {
return sql`
INSERT INTO "jobQueue" ("id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
) VALUES (
${it.id ?? uuid()}, ${it.isComplete ?? false}, ${it.priority ?? 0}, ${
it.scheduledAt ?? new Date()
}, ${it.name ?? null}, ${JSON.stringify(it.data ?? {})}, ${
it.createdAt ?? new Date()
}, ${it.updatedAt ?? new Date()}
) ON CONFLICT("createdAt") DO UPDATE SET
"isComplete" = EXCLUDED."isComplete", "priority" = EXCLUDED."priority", "scheduledAt" = EXCLUDED."scheduledAt", "name" = EXCLUDED."name", "data" = EXCLUDED."data", "updatedAt" = EXCLUDED."updatedAt"
RETURNING "id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
`;
},
/**
* Note: Use only when updatedAt has a unique constraint
* @param sql
* @param { StoreJobQueueInsertPartial_Input & { id?: number } } it
* @returns {Promise<StoreJobQueue[]>}
*/
jobQueueUpsertByUpdatedAt: (sql, it) => {
return sql`
INSERT INTO "jobQueue" ("id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
) VALUES (
${it.id ?? uuid()}, ${it.isComplete ?? false}, ${it.priority ?? 0}, ${
it.scheduledAt ?? new Date()
}, ${it.name ?? null}, ${JSON.stringify(it.data ?? {})}, ${
it.createdAt ?? new Date()
}, ${it.updatedAt ?? new Date()}
) ON CONFLICT("updatedAt") DO UPDATE SET
"isComplete" = EXCLUDED."isComplete", "priority" = EXCLUDED."priority", "scheduledAt" = EXCLUDED."scheduledAt", "name" = EXCLUDED."name", "data" = EXCLUDED."data"
RETURNING "id", "isComplete", "priority", "scheduledAt", "name", "data", "createdAt", "updatedAt"
`;
},
/**
* @param sql
* @param { StoreSessionStoreWhere} [where]

@@ -484,3 +849,27 @@ * @returns {Promise<StoreSessionStore[]>}

where?.expiresLowerThan ?? null
}, NULL) IS NULL OR ss."expires" < ${where?.expiresLowerThan ?? null})
}, NULL) IS NULL OR ss."expires" < ${
where?.expiresLowerThan ?? null
}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR ss."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR ss."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR ss."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR ss."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR ss."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR ss."updatedAt" < ${where?.updatedAtLowerThan ?? null})
ORDER BY ss."createdAt", ss."updatedAt" , ss."id"

@@ -513,3 +902,27 @@ `,

where?.expiresLowerThan ?? null
}, NULL) IS NULL OR ss."expires" < ${where?.expiresLowerThan ?? null})
}, NULL) IS NULL OR ss."expires" < ${
where?.expiresLowerThan ?? null
}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR ss."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR ss."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR ss."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR ss."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR ss."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR ss."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`;

@@ -540,3 +953,27 @@ return parseInt(result?.[0]?.genCount ?? "0");

where?.expiresLowerThan ?? null
}, NULL) IS NULL OR ss."expires" < ${where?.expiresLowerThan ?? null})
}, NULL) IS NULL OR ss."expires" < ${
where?.expiresLowerThan ?? null
}) AND (COALESCE(${
where?.createdAt ?? null
}, NULL) IS NULL OR ss."createdAt" = ${
where?.createdAt ?? null
}) AND (COALESCE(${
where?.createdAtGreaterThan ?? null
}, NULL) IS NULL OR ss."createdAt" > ${
where?.createdAtGreaterThan ?? null
}) AND (COALESCE(${
where?.createdAtLowerThan ?? null
}, NULL) IS NULL OR ss."createdAt" < ${
where?.createdAtLowerThan ?? null
}) AND (COALESCE(${
where?.updatedAt ?? null
}, NULL) IS NULL OR ss."updatedAt" = ${
where?.updatedAt ?? null
}) AND (COALESCE(${
where?.updatedAtGreaterThan ?? null
}, NULL) IS NULL OR ss."updatedAt" > ${
where?.updatedAtGreaterThan ?? null
}) AND (COALESCE(${
where?.updatedAtLowerThan ?? null
}, NULL) IS NULL OR ss."updatedAt" < ${where?.updatedAtLowerThan ?? null})
`,

@@ -637,2 +1074,38 @@

}
if (where.createdAt !== undefined) {
query += `ss."createdAt" `;
query += `= $${idx++}`;
argList.push(where.createdAt);
query += " AND ";
}
if (where.createdAtGreaterThan !== undefined) {
query += `ss."createdAt" `;
query += `> $${idx++}`;
argList.push(where.createdAtGreaterThan);
query += " AND ";
}
if (where.createdAtLowerThan !== undefined) {
query += `ss."createdAt" `;
query += `< $${idx++}`;
argList.push(where.createdAtLowerThan);
query += " AND ";
}
if (where.updatedAt !== undefined) {
query += `ss."updatedAt" `;
query += `= $${idx++}`;
argList.push(where.updatedAt);
query += " AND ";
}
if (where.updatedAtGreaterThan !== undefined) {
query += `ss."updatedAt" `;
query += `> $${idx++}`;
argList.push(where.updatedAtGreaterThan);
query += " AND ";
}
if (where.updatedAtLowerThan !== undefined) {
query += `ss."updatedAt" `;
query += `< $${idx++}`;
argList.push(where.updatedAtLowerThan);
query += " AND ";
}
query = query.substring(0, query.length - 4);

@@ -680,2 +1153,40 @@ query += ` RETURNING ss."id", ss."expires", ss."data", ss."createdAt", ss."updatedAt"`;

},
/**
* Note: Use only when createdAt has a unique constraint
* @param sql
* @param { StoreSessionStoreInsertPartial_Input & { id?: string } } it
* @returns {Promise<StoreSessionStore[]>}
*/
sessionStoreUpsertByCreatedAt: (sql, it) => {
return sql`
INSERT INTO "sessionStore" ("id", "expires", "data", "createdAt", "updatedAt"
) VALUES (
${it.id ?? uuid()}, ${it.expires ?? null}, ${JSON.stringify(it.data ?? {})}, ${
it.createdAt ?? new Date()
}, ${it.updatedAt ?? new Date()}
) ON CONFLICT("createdAt") DO UPDATE SET
"expires" = EXCLUDED."expires", "data" = EXCLUDED."data", "updatedAt" = EXCLUDED."updatedAt"
RETURNING "id", "expires", "data", "createdAt", "updatedAt"
`;
},
/**
* Note: Use only when updatedAt has a unique constraint
* @param sql
* @param { StoreSessionStoreInsertPartial_Input & { id?: string } } it
* @returns {Promise<StoreSessionStore[]>}
*/
sessionStoreUpsertByUpdatedAt: (sql, it) => {
return sql`
INSERT INTO "sessionStore" ("id", "expires", "data", "createdAt", "updatedAt"
) VALUES (
${it.id ?? uuid()}, ${it.expires ?? null}, ${JSON.stringify(it.data ?? {})}, ${
it.createdAt ?? new Date()
}, ${it.updatedAt ?? new Date()}
) ON CONFLICT("updatedAt") DO UPDATE SET
"expires" = EXCLUDED."expires", "data" = EXCLUDED."data"
RETURNING "id", "expires", "data", "createdAt", "updatedAt"
`;
},
};

@@ -31,3 +31,3 @@ // Generated by @lbu/code-gen

*
* @typedef { { "id"?:string, "idIn"?:(string)[] , "bucketName"?:string , "bucketNameLike"?:string , }}
* @typedef { { "id"?:string, "idIn"?:(string)[] , "bucketName"?:string , "bucketNameLike"?:string , "createdAt":Date, "createdAtGreaterThan":Date, "createdAtLowerThan":Date, "updatedAt":Date, "updatedAtGreaterThan":Date, "updatedAtLowerThan":Date, }}
*/

@@ -38,3 +38,3 @@

*
* @typedef { StoreFileStoreWhere}
* @typedef { { "id"?:string, "idIn"?:(string)[] , "bucketName"?:string , "bucketNameLike"?:string , "createdAt"?:string, "createdAtGreaterThan"?:string, "createdAtLowerThan"?:string, "updatedAt"?:string, "updatedAtGreaterThan"?:string, "updatedAtLowerThan"?:string, }}
*/

@@ -69,3 +69,3 @@

*
* @typedef { { "id"?:number , "idGreaterThan"?:number , "idLowerThan"?:number , "name"?:string , "nameLike"?:string , }}
* @typedef { { "id"?:number , "idGreaterThan"?:number , "idLowerThan"?:number , "scheduledAt":Date, "scheduledAtGreaterThan":Date, "scheduledAtLowerThan":Date, "name"?:string , "nameLike"?:string , "createdAt":Date, "createdAtGreaterThan":Date, "createdAtLowerThan":Date, "updatedAt":Date, "updatedAtGreaterThan":Date, "updatedAtLowerThan":Date, }}
*/

@@ -76,3 +76,3 @@

*
* @typedef { StoreJobQueueWhere}
* @typedef { { "id"?:number , "idGreaterThan"?:number , "idLowerThan"?:number , "scheduledAt"?:string, "scheduledAtGreaterThan"?:string, "scheduledAtLowerThan"?:string, "name"?:string , "nameLike"?:string , "createdAt"?:string, "createdAtGreaterThan"?:string, "createdAtLowerThan"?:string, "updatedAt"?:string, "updatedAtGreaterThan"?:string, "updatedAtLowerThan"?:string, }}
*/

@@ -107,3 +107,3 @@

*
* @typedef { { "id"?:string, "idIn"?:(string)[] , "expires"?:Date, "expiresGreaterThan"?:Date, "expiresLowerThan"?:Date, }}
* @typedef { { "id"?:string, "idIn"?:(string)[] , "expires"?:Date, "expiresGreaterThan"?:Date, "expiresLowerThan"?:Date, "createdAt":Date, "createdAtGreaterThan":Date, "createdAtLowerThan":Date, "updatedAt":Date, "updatedAtGreaterThan":Date, "updatedAtLowerThan":Date, }}
*/

@@ -114,3 +114,3 @@

*
* @typedef { { "id"?:string, "idIn"?:(string)[] , "expires"?:string, "expiresGreaterThan"?:string, "expiresLowerThan"?:string, }}
* @typedef { { "id"?:string, "idIn"?:(string)[] , "expires"?:string, "expiresGreaterThan"?:string, "expiresLowerThan"?:string, "createdAt"?:string, "createdAtGreaterThan"?:string, "createdAtLowerThan"?:string, "updatedAt"?:string, "updatedAtGreaterThan"?:string, "updatedAtLowerThan"?:string, }}
*/

@@ -44,2 +44,3 @@ import { isProduction, merge } from "@lbu/stdlib";

},
no_prepare: true,
},

@@ -46,0 +47,0 @@ opts,

@@ -104,4 +104,4 @@ import { log } from "@lbu/insight";

await Promise.all([
creationSql.end({ timeout: 0.01 }),
sql.end({ timeout: 0.01 }),
creationSql.end({ timeout: 0.2 }),
sql.end({ timeout: 0.2 }),
]);

@@ -124,3 +124,3 @@ }

await Promise.all([
creationSql.end({ timeout: 0.01 }),
creationSql.end({ timeout: 0.2 }),
sql`SELECT 1 + 1 AS sum`,

@@ -137,3 +137,3 @@ ]);

const dbName = sql.options.database;
await sql.end({ timeout: 0.01 });
await sql.end({ timeout: 0.2 });

@@ -143,3 +143,3 @@ const deletionSql = await newPostgresConnection({});

await deletionSql.unsafe(`DROP DATABASE ${dbName}`);
await deletionSql.end({ timeout: 0.01 });
await deletionSql.end({ timeout: 0.2 });
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc