ras-stack 5.5.6 → 6.0.1
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/README.md +32 -34
- package/config/oxlint.json +1 -0
- package/dist/cli.d.ts +0 -27
- package/dist/cli.js +4 -32
- package/dist/cli.js.map +1 -1
- package/package.json +12 -228
- package/config/vite.mjs +0 -3
- package/dist/auth/client.d.ts +0 -11
- package/dist/auth/client.js +0 -57
- package/dist/auth/client.js.map +0 -1
- package/dist/auth/index.d.ts +0 -9
- package/dist/auth/index.js +0 -6
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/origins.d.ts +0 -13
- package/dist/auth/origins.js +0 -41
- package/dist/auth/origins.js.map +0 -1
- package/dist/auth/providers.d.ts +0 -11
- package/dist/auth/providers.js +0 -26
- package/dist/auth/providers.js.map +0 -1
- package/dist/auth/random.d.ts +0 -2
- package/dist/auth/random.js +0 -10
- package/dist/auth/random.js.map +0 -1
- package/dist/auth/react.d.ts +0 -18
- package/dist/auth/react.js +0 -34
- package/dist/auth/react.js.map +0 -1
- package/dist/auth/secret.d.ts +0 -8
- package/dist/auth/secret.js +0 -44
- package/dist/auth/secret.js.map +0 -1
- package/dist/auth/settings.d.ts +0 -54
- package/dist/auth/settings.js +0 -37
- package/dist/auth/settings.js.map +0 -1
- package/dist/build/cli.d.ts +0 -1
- package/dist/build/cli.js +0 -24
- package/dist/build/cli.js.map +0 -1
- package/dist/build/index.d.ts +0 -17
- package/dist/build/index.js +0 -93
- package/dist/build/index.js.map +0 -1
- package/dist/changesets/cli.d.ts +0 -1
- package/dist/changesets/cli.js +0 -14
- package/dist/changesets/cli.js.map +0 -1
- package/dist/changesets/index.d.ts +0 -1
- package/dist/changesets/index.js +0 -38
- package/dist/changesets/index.js.map +0 -1
- package/dist/config.d.ts +0 -3
- package/dist/config.js +0 -3
- package/dist/config.js.map +0 -1
- package/dist/conformance/index.d.ts +0 -9
- package/dist/conformance/index.js +0 -92
- package/dist/conformance/index.js.map +0 -1
- package/dist/database/index.d.ts +0 -19
- package/dist/database/index.js +0 -21
- package/dist/database/index.js.map +0 -1
- package/dist/database/libsql.d.ts +0 -14
- package/dist/database/libsql.js +0 -31
- package/dist/database/libsql.js.map +0 -1
- package/dist/database/postgres.d.ts +0 -13
- package/dist/database/postgres.js +0 -16
- package/dist/database/postgres.js.map +0 -1
- package/dist/database/pragmas.d.ts +0 -7
- package/dist/database/pragmas.js +0 -12
- package/dist/database/pragmas.js.map +0 -1
- package/dist/database/sqlite.d.ts +0 -20
- package/dist/database/sqlite.js +0 -45
- package/dist/database/sqlite.js.map +0 -1
- package/dist/email/index.d.ts +0 -63
- package/dist/email/index.js +0 -95
- package/dist/email/index.js.map +0 -1
- package/dist/managed/catalog.d.ts +0 -40
- package/dist/managed/catalog.js +0 -114
- package/dist/managed/catalog.js.map +0 -1
- package/dist/managed/cli.d.ts +0 -1
- package/dist/managed/cli.js +0 -54
- package/dist/managed/cli.js.map +0 -1
- package/dist/managed/environment.d.ts +0 -5
- package/dist/managed/environment.js +0 -52
- package/dist/managed/environment.js.map +0 -1
- package/dist/managed/files.d.ts +0 -4
- package/dist/managed/files.js +0 -30
- package/dist/managed/files.js.map +0 -1
- package/dist/managed/install.d.ts +0 -4
- package/dist/managed/install.js +0 -62
- package/dist/managed/install.js.map +0 -1
- package/dist/managed/model.d.ts +0 -24
- package/dist/managed/model.js +0 -30
- package/dist/managed/model.js.map +0 -1
- package/dist/managed/plan.d.ts +0 -13
- package/dist/managed/plan.js +0 -99
- package/dist/managed/plan.js.map +0 -1
- package/dist/managed/pnpm.d.ts +0 -23
- package/dist/managed/pnpm.js +0 -2808
- package/dist/managed/pnpm.js.map +0 -7
- package/dist/managed/process.d.ts +0 -4
- package/dist/managed/process.js +0 -23
- package/dist/managed/process.js.map +0 -1
- package/dist/managed/sync.d.ts +0 -6
- package/dist/managed/sync.js +0 -96
- package/dist/managed/sync.js.map +0 -1
- package/dist/managed/tools.d.ts +0 -1
- package/dist/managed/tools.js +0 -7
- package/dist/managed/tools.js.map +0 -1
- package/dist/posthog/config.d.ts +0 -19
- package/dist/posthog/config.js +0 -51
- package/dist/posthog/config.js.map +0 -1
- package/dist/posthog/index.d.ts +0 -4
- package/dist/posthog/index.js +0 -3
- package/dist/posthog/index.js.map +0 -1
- package/dist/posthog/proxy.d.ts +0 -30
- package/dist/posthog/proxy.js +0 -51
- package/dist/posthog/proxy.js.map +0 -1
- package/dist/posthog/react.d.ts +0 -39
- package/dist/posthog/react.js +0 -81
- package/dist/posthog/react.js.map +0 -1
- package/dist/posthog/request.d.ts +0 -12
- package/dist/posthog/request.js +0 -22
- package/dist/posthog/request.js.map +0 -1
- package/dist/posthog/server.d.ts +0 -67
- package/dist/posthog/server.js +0 -388
- package/dist/posthog/server.js.map +0 -1
- package/dist/query/index.d.ts +0 -8
- package/dist/query/index.js +0 -17
- package/dist/query/index.js.map +0 -1
- package/dist/realtime/client.d.ts +0 -19
- package/dist/realtime/client.js +0 -37
- package/dist/realtime/client.js.map +0 -1
- package/dist/realtime/environment.d.ts +0 -10
- package/dist/realtime/environment.js +0 -28
- package/dist/realtime/environment.js.map +0 -1
- package/dist/realtime/index.d.ts +0 -6
- package/dist/realtime/index.js +0 -4
- package/dist/realtime/index.js.map +0 -1
- package/dist/realtime/publisher.d.ts +0 -37
- package/dist/realtime/publisher.js +0 -195
- package/dist/realtime/publisher.js.map +0 -1
- package/dist/realtime/react.d.ts +0 -13
- package/dist/realtime/react.js +0 -78
- package/dist/realtime/react.js.map +0 -1
- package/dist/realtime/tokens.d.ts +0 -6
- package/dist/realtime/tokens.js +0 -13
- package/dist/realtime/tokens.js.map +0 -1
- package/dist/runtime/dev.d.ts +0 -21
- package/dist/runtime/dev.js +0 -138
- package/dist/runtime/dev.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -2
- package/dist/runtime/index.js +0 -2
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/stack.d.ts +0 -65
- package/dist/runtime/stack.js +0 -226
- package/dist/runtime/stack.js.map +0 -1
- package/dist/server/canonical-host.d.ts +0 -6
- package/dist/server/canonical-host.js +0 -23
- package/dist/server/canonical-host.js.map +0 -1
- package/dist/server/errors.d.ts +0 -1
- package/dist/server/errors.js +0 -20
- package/dist/server/errors.js.map +0 -1
- package/dist/server/health.d.ts +0 -10
- package/dist/server/health.js +0 -12
- package/dist/server/health.js.map +0 -1
- package/dist/server/index.d.ts +0 -7
- package/dist/server/index.js +0 -5
- package/dist/server/index.js.map +0 -1
- package/dist/server/rpc.d.ts +0 -19
- package/dist/server/rpc.js +0 -52
- package/dist/server/rpc.js.map +0 -1
- package/dist/server/server-function.d.ts +0 -8
- package/dist/server/server-function.js +0 -18
- package/dist/server/server-function.js.map +0 -1
- package/dist/server/singleton.d.ts +0 -4
- package/dist/server/singleton.js +0 -48
- package/dist/server/singleton.js.map +0 -1
- package/dist/spacetime/index.d.ts +0 -36
- package/dist/spacetime/index.js +0 -103
- package/dist/spacetime/index.js.map +0 -1
- package/dist/tanstack/client.d.ts +0 -11
- package/dist/tanstack/client.js +0 -33
- package/dist/tanstack/client.js.map +0 -1
- package/dist/tanstack/middleware.d.ts +0 -9
- package/dist/tanstack/middleware.js +0 -32
- package/dist/tanstack/middleware.js.map +0 -1
- package/dist/tanstack/server.d.ts +0 -10
- package/dist/tanstack/server.js +0 -14
- package/dist/tanstack/server.js.map +0 -1
- package/dist/uploads/index.d.ts +0 -29
- package/dist/uploads/index.js +0 -83
- package/dist/uploads/index.js.map +0 -1
- package/dist/vite/config.d.ts +0 -18
- package/dist/vite/config.js +0 -88
- package/dist/vite/config.js.map +0 -1
- package/dist/vite/index.d.ts +0 -2
- package/dist/vite/index.js +0 -2
- package/dist/vite/index.js.map +0 -1
- package/pnpmfile.mjs +0 -1
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { resolveSqlitePragmas } from '../database/pragmas.js';
|
|
2
|
-
class ConformanceError extends Error {
|
|
3
|
-
scenario;
|
|
4
|
-
constructor(scenario, message, options = {}) {
|
|
5
|
-
super(`${scenario}: ${message}`, options.cause === undefined ? undefined : { cause: options.cause });
|
|
6
|
-
this.scenario = scenario;
|
|
7
|
-
this.name = 'ConformanceError';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export async function assertMutationOriginConformance(guard, options = {}) {
|
|
11
|
-
await accepted('same-origin request', () => guard(new Request('https://app.example/action', {
|
|
12
|
-
method: 'POST',
|
|
13
|
-
headers: { origin: 'https://app.example', 'sec-fetch-site': 'same-origin' },
|
|
14
|
-
})));
|
|
15
|
-
await rejected('cross-origin request', () => guard(new Request('https://app.example/action', {
|
|
16
|
-
method: 'POST',
|
|
17
|
-
headers: { origin: 'https://attacker.example', 'sec-fetch-site': 'cross-site' },
|
|
18
|
-
})));
|
|
19
|
-
await rejected('missing-origin request', () => guard(new Request('https://app.example/action', { method: 'POST' })));
|
|
20
|
-
if (!options.trustForwardedHeaders) {
|
|
21
|
-
await rejected('spoofed forwarded-origin request', () => guard(new Request('https://app.example/action', {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: {
|
|
24
|
-
origin: 'https://attacker.example',
|
|
25
|
-
'x-forwarded-host': 'attacker.example',
|
|
26
|
-
'x-forwarded-proto': 'https',
|
|
27
|
-
},
|
|
28
|
-
})));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const synchronousLevels = { OFF: 0, NORMAL: 1, FULL: 2, EXTRA: 3 };
|
|
32
|
-
export async function assertSqliteConformance(readPragma) {
|
|
33
|
-
const values = {
|
|
34
|
-
journalMode: String(await readPragma('journal_mode')).toLowerCase(),
|
|
35
|
-
synchronous: Number(await readPragma('synchronous')),
|
|
36
|
-
busyTimeout: Number(await readPragma('busy_timeout')),
|
|
37
|
-
foreignKeys: Number(await readPragma('foreign_keys')),
|
|
38
|
-
};
|
|
39
|
-
const expected = resolveSqlitePragmas();
|
|
40
|
-
const journalMode = expected.journalMode.toLowerCase();
|
|
41
|
-
if (values.journalMode !== journalMode && values.journalMode !== 'memory') {
|
|
42
|
-
throw new ConformanceError('SQLite journal mode', `expected ${journalMode} or memory, received ${values.journalMode}`);
|
|
43
|
-
}
|
|
44
|
-
const synchronous = synchronousLevels[expected.synchronous];
|
|
45
|
-
if (values.synchronous !== synchronous) {
|
|
46
|
-
throw new ConformanceError('SQLite synchronous mode', `expected ${expected.synchronous} (${synchronous}), received ${values.synchronous}`);
|
|
47
|
-
}
|
|
48
|
-
if (values.busyTimeout !== expected.busyTimeout) {
|
|
49
|
-
throw new ConformanceError('SQLite busy timeout', `expected ${expected.busyTimeout}, received ${values.busyTimeout}`);
|
|
50
|
-
}
|
|
51
|
-
if (values.foreignKeys !== 1) {
|
|
52
|
-
throw new ConformanceError('SQLite foreign keys', `expected enabled (1), received ${values.foreignKeys}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export function assertDatabaseTargetConformance(resolve) {
|
|
56
|
-
const sqliteFile = '/data/application.sqlite';
|
|
57
|
-
const sqlite = resolve({ sqliteFile });
|
|
58
|
-
if (sqlite.provider !== 'sqlite' || sqlite.file !== sqliteFile) {
|
|
59
|
-
throw new ConformanceError('default database target', 'expected the configured SQLite file');
|
|
60
|
-
}
|
|
61
|
-
for (const url of ['postgres://user:secret@database/application', 'postgresql://user:secret@database/application']) {
|
|
62
|
-
const target = resolve({ databaseUrl: url, sqliteFile });
|
|
63
|
-
if (target.provider !== 'postgres' || target.url !== url) {
|
|
64
|
-
throw new ConformanceError('PostgreSQL database target', `expected the configured ${new URL(url).protocol} URL`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
resolve({ databaseUrl: 'https://database.example/application', sqliteFile });
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
throw new ConformanceError('invalid database target', 'expected a non-PostgreSQL URL to be rejected');
|
|
74
|
-
}
|
|
75
|
-
async function accepted(scenario, work) {
|
|
76
|
-
try {
|
|
77
|
-
await work();
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
throw new ConformanceError(scenario, 'expected request to be accepted', { cause: error });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function rejected(scenario, work) {
|
|
84
|
-
try {
|
|
85
|
-
await work();
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
throw new ConformanceError(scenario, 'expected request to be rejected');
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,wBAAwB,CAAA;AAIjF,MAAM,gBAAiB,SAAQ,KAAK;IAEvB,QAAQ;IADnB,YACW,QAAgB,EACzB,OAAe,EACf,OAAO,GAAwB,EAAE;QAEjC,KAAK,CAAC,GAAG,QAAQ,KAAK,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;wBAJ3F,QAAQ;QAKjB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,KAAiD,EACjD,OAAO,GAAwC,EAAE;IAEjD,MAAM,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE,CACzC,KAAK,CACH,IAAI,OAAO,CAAC,4BAA4B,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAE;KAC5E,CAAC,CACH,CACF,CAAA;IACD,MAAM,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAC1C,KAAK,CACH,IAAI,O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C,CAAC,EAAE,CAAC;QACnH,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAA;QACxD,IAAI,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACzD,MAAM,IAAI,gBAAgB,CAAC,4BAA4B,EAAE,2BAA2B,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAA;QAClH,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACH,OAAO,CAAC,EAAE,WAAW,EAAE,sCAAsC,EAAE,UAAU,EAAE,CAAC,CAAA;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAM;IACR,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,yBAAyB,EAAE,8CAA8C,CAAC,CAAA;AACvG,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAgC;IACxE,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAA;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,iCAAiC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC3F,CAAC;AACH,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAgC;IACxE,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAA;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAM;IACR,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAA;AACzE,CAAC","sourcesContent":["import type { databaseTarget } from '../database/index.js'\nimport { resolveSqlitePragmas, type SqlitePragmas } from '../database/pragmas.js'\n\nexport type { DatabaseTarget } from '../database/index.js'\n\nclass ConformanceError extends Error {\n constructor(\n readonly scenario: string,\n message: string,\n options: { cause?: unknown } = {},\n ) {\n super(`${scenario}: ${message}`, options.cause === undefined ? undefined : { cause: options.cause })\n this.name = 'ConformanceError'\n }\n}\n\nexport async function assertMutationOriginConformance(\n guard: (request: Request) => void | Promise<void>,\n options: { trustForwardedHeaders?: boolean } = {},\n) {\n await accepted('same-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: { origin: 'https://app.example', 'sec-fetch-site': 'same-origin' },\n }),\n ),\n )\n await rejected('cross-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: { origin: 'https://attacker.example', 'sec-fetch-site': 'cross-site' },\n }),\n ),\n )\n await rejected('missing-origin request', () => guard(new Request('https://app.example/action', { method: 'POST' })))\n if (!options.trustForwardedHeaders) {\n await rejected('spoofed forwarded-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: {\n origin: 'https://attacker.example',\n 'x-forwarded-host': 'attacker.example',\n 'x-forwarded-proto': 'https',\n },\n }),\n ),\n )\n }\n}\n\nconst synchronousLevels = { OFF: 0, NORMAL: 1, FULL: 2, EXTRA: 3 } satisfies Record<Required<SqlitePragmas>['synchronous'], number>\n\nexport type SqlitePragmaReader = (name: 'journal_mode' | 'synchronous' | 'busy_timeout' | 'foreign_keys') => unknown\n\nexport async function assertSqliteConformance(readPragma: SqlitePragmaReader) {\n const values = {\n journalMode: String(await readPragma('journal_mode')).toLowerCase(),\n synchronous: Number(await readPragma('synchronous')),\n busyTimeout: Number(await readPragma('busy_timeout')),\n foreignKeys: Number(await readPragma('foreign_keys')),\n }\n const expected = resolveSqlitePragmas()\n const journalMode = expected.journalMode.toLowerCase()\n if (values.journalMode !== journalMode && values.journalMode !== 'memory') {\n throw new ConformanceError('SQLite journal mode', `expected ${journalMode} or memory, received ${values.journalMode}`)\n }\n const synchronous = synchronousLevels[expected.synchronous]\n if (values.synchronous !== synchronous) {\n throw new ConformanceError(\n 'SQLite synchronous mode',\n `expected ${expected.synchronous} (${synchronous}), received ${values.synchronous}`,\n )\n }\n if (values.busyTimeout !== expected.busyTimeout) {\n throw new ConformanceError('SQLite busy timeout', `expected ${expected.busyTimeout}, received ${values.busyTimeout}`)\n }\n if (values.foreignKeys !== 1) {\n throw new ConformanceError('SQLite foreign keys', `expected enabled (1), received ${values.foreignKeys}`)\n }\n}\n\nexport type DatabaseTargetResolver = typeof databaseTarget\n\nexport function assertDatabaseTargetConformance(resolve: DatabaseTargetResolver) {\n const sqliteFile = '/data/application.sqlite'\n const sqlite = resolve({ sqliteFile })\n if (sqlite.provider !== 'sqlite' || sqlite.file !== sqliteFile) {\n throw new ConformanceError('default database target', 'expected the configured SQLite file')\n }\n\n for (const url of ['postgres://user:secret@database/application', 'postgresql://user:secret@database/application']) {\n const target = resolve({ databaseUrl: url, sqliteFile })\n if (target.provider !== 'postgres' || target.url !== url) {\n throw new ConformanceError('PostgreSQL database target', `expected the configured ${new URL(url).protocol} URL`)\n }\n }\n\n try {\n resolve({ databaseUrl: 'https://database.example/application', sqliteFile })\n } catch {\n return\n }\n throw new ConformanceError('invalid database target', 'expected a non-PostgreSQL URL to be rejected')\n}\n\nasync function accepted(scenario: string, work: () => void | Promise<void>) {\n try {\n await work()\n } catch (error) {\n throw new ConformanceError(scenario, 'expected request to be accepted', { cause: error })\n }\n}\n\nasync function rejected(scenario: string, work: () => void | Promise<void>) {\n try {\n await work()\n } catch {\n return\n }\n throw new ConformanceError(scenario, 'expected request to be rejected')\n}\n"]}
|
package/dist/database/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
2
|
-
export type BundledDirectoryOptions = {
|
|
3
|
-
developmentUrl: URL;
|
|
4
|
-
production: boolean;
|
|
5
|
-
productionEntry?: string;
|
|
6
|
-
name: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function bundledDirectory(options: BundledDirectoryOptions): string;
|
|
9
|
-
export type DatabaseTarget = {
|
|
10
|
-
provider: 'sqlite';
|
|
11
|
-
file: string;
|
|
12
|
-
} | {
|
|
13
|
-
provider: 'postgres';
|
|
14
|
-
url: string;
|
|
15
|
-
};
|
|
16
|
-
export declare function databaseTarget(options: {
|
|
17
|
-
databaseUrl?: string;
|
|
18
|
-
sqliteFile: string;
|
|
19
|
-
}): DatabaseTarget;
|
package/dist/database/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileURLToPath, URL } from 'node:url';
|
|
3
|
-
export function bundledDirectory(options) {
|
|
4
|
-
if (!options.production)
|
|
5
|
-
return fileURLToPath(options.developmentUrl);
|
|
6
|
-
const entry = options.productionEntry ?? process.argv[1];
|
|
7
|
-
if (!entry)
|
|
8
|
-
throw new Error('production entrypoint is required to resolve a bundled directory');
|
|
9
|
-
return path.join(path.dirname(entry), options.name);
|
|
10
|
-
}
|
|
11
|
-
export function databaseTarget(options) {
|
|
12
|
-
const configured = options.databaseUrl?.trim();
|
|
13
|
-
if (!configured)
|
|
14
|
-
return { provider: 'sqlite', file: options.sqliteFile };
|
|
15
|
-
const url = new URL(configured);
|
|
16
|
-
if (url.protocol !== 'postgres:' && url.protocol !== 'postgresql:') {
|
|
17
|
-
throw new Error('database URL must use a postgres:// or postgresql:// URL');
|
|
18
|
-
}
|
|
19
|
-
return { provider: 'postgres', url: configured };
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAS7C,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,IAAI,CAAC,OAAO,CAAC,UAAU;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IACrE,MAAM,KAAK,GAAG,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACxD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IAC/F,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;AACrD,CAAC;AAID,MAAM,UAAU,cAAc,CAAC,OAAqD;IAClF,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,CAAA;IAC9C,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,CAAA;IACxE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;IAC/B,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,IAAI,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAA;IAC7E,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,CAAA;AAClD,CAAC","sourcesContent":["import path from 'node:path'\nimport { fileURLToPath, URL } from 'node:url'\n\nexport type BundledDirectoryOptions = {\n developmentUrl: URL\n production: boolean\n productionEntry?: string\n name: string\n}\n\nexport function bundledDirectory(options: BundledDirectoryOptions) {\n if (!options.production) return fileURLToPath(options.developmentUrl)\n const entry = options.productionEntry ?? process.argv[1]\n if (!entry) throw new Error('production entrypoint is required to resolve a bundled directory')\n return path.join(path.dirname(entry), options.name)\n}\n\nexport type DatabaseTarget = { provider: 'sqlite'; file: string } | { provider: 'postgres'; url: string }\n\nexport function databaseTarget(options: { databaseUrl?: string; sqliteFile: string }): DatabaseTarget {\n const configured = options.databaseUrl?.trim()\n if (!configured) return { provider: 'sqlite', file: options.sqliteFile }\n const url = new URL(configured)\n if (url.protocol !== 'postgres:' && url.protocol !== 'postgresql:') {\n throw new Error('database URL must use a postgres:// or postgresql:// URL')\n }\n return { provider: 'postgres', url: configured }\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type Client, type Config } from '@libsql/client';
|
|
2
|
-
import { type LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
3
|
-
import { type SqlitePragmas } from './pragmas.js';
|
|
4
|
-
export type LibsqlPragmas = Pick<SqlitePragmas, 'journalMode' | 'busyTimeout'>;
|
|
5
|
-
export type OpenDrizzleLibsqlOptions<TSchema extends Record<string, unknown>> = {
|
|
6
|
-
file: string;
|
|
7
|
-
schema: TSchema;
|
|
8
|
-
migrationsFolder?: string;
|
|
9
|
-
client?: Omit<Config, 'url'>;
|
|
10
|
-
pragmas?: LibsqlPragmas | false;
|
|
11
|
-
};
|
|
12
|
-
export declare function openDrizzleLibsql<TSchema extends Record<string, unknown>>(options: OpenDrizzleLibsqlOptions<TSchema>): Promise<LibSQLDatabase<TSchema> & {
|
|
13
|
-
$client: Client;
|
|
14
|
-
}>;
|
package/dist/database/libsql.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createClient } from '@libsql/client';
|
|
2
|
-
import { drizzle } from 'drizzle-orm/libsql';
|
|
3
|
-
import { migrate } from 'drizzle-orm/libsql/migrator';
|
|
4
|
-
import { mkdirSync } from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { pathToFileURL } from 'node:url';
|
|
7
|
-
import { resolveSqlitePragmas } from './pragmas.js';
|
|
8
|
-
export async function openDrizzleLibsql(options) {
|
|
9
|
-
const memory = options.file === ':memory:';
|
|
10
|
-
const pragmas = options.pragmas === false ? undefined : resolveSqlitePragmas(options.pragmas);
|
|
11
|
-
if (!memory)
|
|
12
|
-
mkdirSync(path.dirname(path.resolve(options.file)), { recursive: true });
|
|
13
|
-
const client = createClient({
|
|
14
|
-
url: memory ? ':memory:' : pathToFileURL(path.resolve(options.file)).href,
|
|
15
|
-
...(pragmas ? { timeout: pragmas.busyTimeout } : {}),
|
|
16
|
-
...options.client,
|
|
17
|
-
});
|
|
18
|
-
try {
|
|
19
|
-
if (pragmas)
|
|
20
|
-
await client.execute(`pragma journal_mode = ${pragmas.journalMode}`);
|
|
21
|
-
const database = drizzle({ client, schema: options.schema });
|
|
22
|
-
if (options.migrationsFolder)
|
|
23
|
-
await migrate(database, { migrationsFolder: options.migrationsFolder });
|
|
24
|
-
return database;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
client.close();
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=libsql.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libsql.js","sourceRoot":"","sources":["../../src/database/libsql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAE,OAAO,EAAuB,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAsB,MAAM,cAAc,CAAA;AAevE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA0C;IAE1C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,UAAU,CAAA;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7F,IAAI,CAAC,MAAM;QAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACrF,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;QACzE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,GAAG,OAAO,CAAC,MAAM;KAClB,CAAC,CAAA;IACF,IAAI,CAAC;QACH,IAAI,OAAO;YAAE,MAAM,MAAM,CAAC,OAAO,CAAC,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;QACjF,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QAC5D,IAAI,OAAO,CAAC,gBAAgB;YAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;QACrG,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { createClient, type Client, type Config } from '@libsql/client'\nimport { drizzle, type LibSQLDatabase } from 'drizzle-orm/libsql'\nimport { migrate } from 'drizzle-orm/libsql/migrator'\nimport { mkdirSync } from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { resolveSqlitePragmas, type SqlitePragmas } from './pragmas.js'\n\n// The client pools connections and opens each with libsql's defaults, so a per-connection pragma run through `execute`\n// reaches only one of them. Those defaults are already synchronous FULL and foreign keys on; the busy timeout goes\n// through `timeout`, which every connection receives, and WAL persists in the file once set.\nexport type LibsqlPragmas = Pick<SqlitePragmas, 'journalMode' | 'busyTimeout'>\n\nexport type OpenDrizzleLibsqlOptions<TSchema extends Record<string, unknown>> = {\n file: string\n schema: TSchema\n migrationsFolder?: string\n client?: Omit<Config, 'url'>\n pragmas?: LibsqlPragmas | false\n}\n\nexport async function openDrizzleLibsql<TSchema extends Record<string, unknown>>(\n options: OpenDrizzleLibsqlOptions<TSchema>,\n): Promise<LibSQLDatabase<TSchema> & { $client: Client }> {\n const memory = options.file === ':memory:'\n const pragmas = options.pragmas === false ? undefined : resolveSqlitePragmas(options.pragmas)\n if (!memory) mkdirSync(path.dirname(path.resolve(options.file)), { recursive: true })\n const client = createClient({\n url: memory ? ':memory:' : pathToFileURL(path.resolve(options.file)).href,\n ...(pragmas ? { timeout: pragmas.busyTimeout } : {}),\n ...options.client,\n })\n try {\n if (pragmas) await client.execute(`pragma journal_mode = ${pragmas.journalMode}`)\n const database = drizzle({ client, schema: options.schema })\n if (options.migrationsFolder) await migrate(database, { migrationsFolder: options.migrationsFolder })\n return database\n } catch (error) {\n client.close()\n throw error\n }\n}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
2
|
-
import postgres, { type Sql } from 'postgres';
|
|
3
|
-
export type PostgresClientOptions = NonNullable<Parameters<typeof postgres>[1]>;
|
|
4
|
-
export type OpenDrizzlePostgresOptions<TSchema extends Record<string, unknown>> = {
|
|
5
|
-
url: string;
|
|
6
|
-
schema: TSchema;
|
|
7
|
-
client?: PostgresClientOptions;
|
|
8
|
-
};
|
|
9
|
-
export type DrizzlePostgresConnection<TSchema extends Record<string, unknown>> = {
|
|
10
|
-
database: PostgresJsDatabase<TSchema>;
|
|
11
|
-
client: Sql;
|
|
12
|
-
};
|
|
13
|
-
export declare function openDrizzlePostgres<TSchema extends Record<string, unknown>>(options: OpenDrizzlePostgresOptions<TSchema>): DrizzlePostgresConnection<TSchema>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
|
-
import postgres, {} from 'postgres';
|
|
3
|
-
export function openDrizzlePostgres(options) {
|
|
4
|
-
const client = postgres(options.url, {
|
|
5
|
-
max: 10,
|
|
6
|
-
onnotice: () => undefined,
|
|
7
|
-
types: {
|
|
8
|
-
bigint: { to: 20, from: [20], serialize: (value) => String(value), parse: Number },
|
|
9
|
-
numeric: { to: 1700, from: [1700], serialize: (value) => String(value), parse: Number },
|
|
10
|
-
},
|
|
11
|
-
...options.client,
|
|
12
|
-
});
|
|
13
|
-
const database = drizzle(client, { schema: options.schema });
|
|
14
|
-
return { database, client };
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=postgres.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/database/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,MAAM,yBAAyB,CAAA;AAC1E,OAAO,QAAQ,EAAE,EAAY,MAAM,UAAU,CAAA;AAe7C,MAAM,UAAU,mBAAmB,CACjC,OAA4C;IAE5C,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;QACnC,GAAG,EAAE,EAAE;QACP,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;QACzB,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;YAC1F,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;SAChG;QACD,GAAG,OAAO,CAAC,MAAM;KAClB,CAAC,CAAA;IACF,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import { drizzle, type PostgresJsDatabase } from 'drizzle-orm/postgres-js'\nimport postgres, { type Sql } from 'postgres'\n\nexport type PostgresClientOptions = NonNullable<Parameters<typeof postgres>[1]>\n\nexport type OpenDrizzlePostgresOptions<TSchema extends Record<string, unknown>> = {\n url: string\n schema: TSchema\n client?: PostgresClientOptions\n}\n\nexport type DrizzlePostgresConnection<TSchema extends Record<string, unknown>> = {\n database: PostgresJsDatabase<TSchema>\n client: Sql\n}\n\nexport function openDrizzlePostgres<TSchema extends Record<string, unknown>>(\n options: OpenDrizzlePostgresOptions<TSchema>,\n): DrizzlePostgresConnection<TSchema> {\n const client = postgres(options.url, {\n max: 10,\n onnotice: () => undefined,\n types: {\n bigint: { to: 20, from: [20], serialize: (value: number) => String(value), parse: Number },\n numeric: { to: 1700, from: [1700], serialize: (value: number) => String(value), parse: Number },\n },\n ...options.client,\n })\n const database = drizzle(client, { schema: options.schema })\n return { database, client }\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type SqlitePragmas = {
|
|
2
|
-
journalMode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF';
|
|
3
|
-
synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';
|
|
4
|
-
busyTimeout?: number;
|
|
5
|
-
foreignKeys?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function resolveSqlitePragmas(pragmas?: SqlitePragmas): Required<SqlitePragmas>;
|
package/dist/database/pragmas.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function resolveSqlitePragmas(pragmas = {}) {
|
|
2
|
-
const busyTimeout = pragmas.busyTimeout ?? 5000;
|
|
3
|
-
if (!Number.isInteger(busyTimeout) || busyTimeout < 0)
|
|
4
|
-
throw new Error('busyTimeout must be a non-negative integer');
|
|
5
|
-
return {
|
|
6
|
-
journalMode: pragmas.journalMode ?? 'WAL',
|
|
7
|
-
synchronous: pragmas.synchronous ?? 'FULL',
|
|
8
|
-
busyTimeout,
|
|
9
|
-
foreignKeys: pragmas.foreignKeys ?? true,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=pragmas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pragmas.js","sourceRoot":"","sources":["../../src/database/pragmas.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAAkB,EAAE;IAC9D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAA;IAC/C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IACpH,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;QACzC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,MAAM;QAC1C,WAAW;QACX,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI;KACzC,CAAA;AACH,CAAC","sourcesContent":["export type SqlitePragmas = {\n journalMode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF'\n synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA'\n busyTimeout?: number\n foreignKeys?: boolean\n}\n\nexport function resolveSqlitePragmas(pragmas: SqlitePragmas = {}): Required<SqlitePragmas> {\n const busyTimeout = pragmas.busyTimeout ?? 5000\n if (!Number.isInteger(busyTimeout) || busyTimeout < 0) throw new Error('busyTimeout must be a non-negative integer')\n return {\n journalMode: pragmas.journalMode ?? 'WAL',\n synchronous: pragmas.synchronous ?? 'FULL',\n busyTimeout,\n foreignKeys: pragmas.foreignKeys ?? true,\n }\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import { type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
3
|
-
import { type SqlitePragmas } from './pragmas.js';
|
|
4
|
-
export type { SqlitePragmas } from './pragmas.js';
|
|
5
|
-
export type OpenSqliteOptions = {
|
|
6
|
-
database?: Database.Options;
|
|
7
|
-
pragmas?: SqlitePragmas | false;
|
|
8
|
-
};
|
|
9
|
-
export declare function openSqliteClient(file: string, options?: OpenSqliteOptions): Database.Database;
|
|
10
|
-
export type OpenDrizzleSqliteOptions<TSchema extends Record<string, unknown>> = OpenSqliteOptions & {
|
|
11
|
-
file: string;
|
|
12
|
-
schema: TSchema;
|
|
13
|
-
migrationsFolder?: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function openDrizzleSqlite<TSchema extends Record<string, unknown>>(options: OpenDrizzleSqliteOptions<TSchema>): BetterSQLite3Database<TSchema> & {
|
|
16
|
-
$client: Database.Database;
|
|
17
|
-
};
|
|
18
|
-
export declare function closeDrizzleSqlite(database: {
|
|
19
|
-
$client: Database.Database;
|
|
20
|
-
}): void;
|
package/dist/database/sqlite.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
3
|
-
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
4
|
-
import { mkdirSync } from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { resolveSqlitePragmas } from './pragmas.js';
|
|
7
|
-
export function openSqliteClient(file, options = {}) {
|
|
8
|
-
if (file !== ':memory:')
|
|
9
|
-
mkdirSync(path.dirname(path.resolve(file)), { recursive: true });
|
|
10
|
-
const client = new Database(file, options.database);
|
|
11
|
-
try {
|
|
12
|
-
if (options.pragmas !== false)
|
|
13
|
-
configureSqlite(client, options.pragmas);
|
|
14
|
-
return client;
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
client.close();
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function configureSqlite(client, pragmas = {}) {
|
|
22
|
-
const { journalMode, synchronous, busyTimeout, foreignKeys } = resolveSqlitePragmas(pragmas);
|
|
23
|
-
client.pragma(`journal_mode = ${journalMode}`);
|
|
24
|
-
client.pragma(`synchronous = ${synchronous}`);
|
|
25
|
-
client.pragma(`busy_timeout = ${busyTimeout}`);
|
|
26
|
-
client.pragma(`foreign_keys = ${foreignKeys ? 'ON' : 'OFF'}`);
|
|
27
|
-
return client;
|
|
28
|
-
}
|
|
29
|
-
export function openDrizzleSqlite(options) {
|
|
30
|
-
const client = openSqliteClient(options.file, options);
|
|
31
|
-
try {
|
|
32
|
-
const database = drizzle({ client, schema: options.schema });
|
|
33
|
-
if (options.migrationsFolder)
|
|
34
|
-
migrate(database, { migrationsFolder: options.migrationsFolder });
|
|
35
|
-
return database;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
client.close();
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function closeDrizzleSqlite(database) {
|
|
43
|
-
database.$client.close();
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=sqlite.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/database/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,OAAO,EAA8B,MAAM,4BAA4B,CAAA;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,O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B,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACtD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QAC5D,IAAI,OAAO,CAAC,gBAAgB;YAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;QAC/F,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAAwC;IACzE,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["import Database from 'better-sqlite3'\nimport { drizzle, type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'\nimport { migrate } from 'drizzle-orm/better-sqlite3/migrator'\nimport { mkdirSync } from 'node:fs'\nimport path from 'node:path'\nimport { resolveSqlitePragmas, type SqlitePragmas } from './pragmas.js'\n\nexport type { SqlitePragmas } from './pragmas.js'\n\nexport type OpenSqliteOptions = {\n database?: Database.Options\n pragmas?: SqlitePragmas | false\n}\n\nexport function openSqliteClient(file: string, options: OpenSqliteOptions = {}): Database.Database {\n if (file !== ':memory:') mkdirSync(path.dirname(path.resolve(file)), { recursive: true })\n const client = new Database(file, options.database)\n try {\n if (options.pragmas !== false) configureSqlite(client, options.pragmas)\n return client\n } catch (error) {\n client.close()\n throw error\n }\n}\n\nfunction configureSqlite(client: Database.Database, pragmas: SqlitePragmas = {}): Database.Database {\n const { journalMode, synchronous, busyTimeout, foreignKeys } = resolveSqlitePragmas(pragmas)\n client.pragma(`journal_mode = ${journalMode}`)\n client.pragma(`synchronous = ${synchronous}`)\n client.pragma(`busy_timeout = ${busyTimeout}`)\n client.pragma(`foreign_keys = ${foreignKeys ? 'ON' : 'OFF'}`)\n return client\n}\n\nexport type OpenDrizzleSqliteOptions<TSchema extends Record<string, unknown>> = OpenSqliteOptions & {\n file: string\n schema: TSchema\n migrationsFolder?: string\n}\n\nexport function openDrizzleSqlite<TSchema extends Record<string, unknown>>(\n options: OpenDrizzleSqliteOptions<TSchema>,\n): BetterSQLite3Database<TSchema> & { $client: Database.Database } {\n const client = openSqliteClient(options.file, options)\n try {\n const database = drizzle({ client, schema: options.schema })\n if (options.migrationsFolder) migrate(database, { migrationsFolder: options.migrationsFolder })\n return database\n } catch (error) {\n client.close()\n throw error\n }\n}\n\nexport function closeDrizzleSqlite(database: { $client: Database.Database }) {\n database.$client.close()\n}\n"]}
|
package/dist/email/index.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/** `cid` lets the HTML body reference the attachment inline as `cid:<value>`. */
|
|
2
|
-
export type EmailAttachment = {
|
|
3
|
-
filename: string;
|
|
4
|
-
content: Buffer;
|
|
5
|
-
contentType: string;
|
|
6
|
-
cid?: string;
|
|
7
|
-
};
|
|
8
|
-
export type EmailMessage = {
|
|
9
|
-
to: string;
|
|
10
|
-
subject: string;
|
|
11
|
-
text: string;
|
|
12
|
-
html?: string;
|
|
13
|
-
attachments?: EmailAttachment[];
|
|
14
|
-
/** Replaces the display name of the configured sender; the address stays the configured one so SPF and DKIM still pass. */
|
|
15
|
-
fromName?: string;
|
|
16
|
-
replyTo?: string;
|
|
17
|
-
};
|
|
18
|
-
export type SmtpConfig = {
|
|
19
|
-
from: string;
|
|
20
|
-
host: string;
|
|
21
|
-
port: number;
|
|
22
|
-
secure: boolean;
|
|
23
|
-
user?: string;
|
|
24
|
-
password?: string;
|
|
25
|
-
/** The name TLS presents and verifies when `host` is an address the application already resolved. */
|
|
26
|
-
servername?: string;
|
|
27
|
-
/** Fails and disconnects a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */
|
|
28
|
-
timeoutMs?: number;
|
|
29
|
-
};
|
|
30
|
-
export type SmtpEnvironmentOptions = {
|
|
31
|
-
host?: string;
|
|
32
|
-
port?: string;
|
|
33
|
-
secure?: string;
|
|
34
|
-
user?: string;
|
|
35
|
-
password?: string;
|
|
36
|
-
from?: string;
|
|
37
|
-
};
|
|
38
|
-
export type EmailDelivery = {
|
|
39
|
-
send(message: EmailMessage): Promise<void>;
|
|
40
|
-
verify(): Promise<void>;
|
|
41
|
-
};
|
|
42
|
-
export type AuthEmailInput<User extends {
|
|
43
|
-
email: string;
|
|
44
|
-
} = {
|
|
45
|
-
email: string;
|
|
46
|
-
}> = {
|
|
47
|
-
user: User;
|
|
48
|
-
url: string;
|
|
49
|
-
token: string;
|
|
50
|
-
};
|
|
51
|
-
export declare function smtpConfigFromEnvironment(environment?: NodeJS.ProcessEnv, keys?: SmtpEnvironmentOptions): SmtpConfig | undefined;
|
|
52
|
-
export declare function createSmtpDelivery(config: SmtpConfig): EmailDelivery;
|
|
53
|
-
export type StandardAuthEmailOptions = {
|
|
54
|
-
productName: string;
|
|
55
|
-
};
|
|
56
|
-
export declare function standardAuthEmails<User extends {
|
|
57
|
-
email: string;
|
|
58
|
-
} = {
|
|
59
|
-
email: string;
|
|
60
|
-
}>(delivery: EmailDelivery, options: StandardAuthEmailOptions): {
|
|
61
|
-
sendResetPassword: ({ user, url }: AuthEmailInput<User>) => Promise<void>;
|
|
62
|
-
sendVerificationEmail: ({ user, url }: AuthEmailInput<User>) => Promise<void>;
|
|
63
|
-
};
|
package/dist/email/index.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import net from 'node:net';
|
|
2
|
-
import { createTransport } from 'nodemailer';
|
|
3
|
-
export function smtpConfigFromEnvironment(environment = process.env, keys = {}) {
|
|
4
|
-
const host = environment[keys.host ?? 'SMTP_HOST']?.trim();
|
|
5
|
-
const from = environment[keys.from ?? 'EMAIL_FROM']?.trim();
|
|
6
|
-
if (!host && !from)
|
|
7
|
-
return undefined;
|
|
8
|
-
if (!host)
|
|
9
|
-
throw new Error(`${keys.host ?? 'SMTP_HOST'} is required for SMTP email`);
|
|
10
|
-
if (!from)
|
|
11
|
-
throw new Error(`${keys.from ?? 'EMAIL_FROM'} is required for SMTP email`);
|
|
12
|
-
const portKey = keys.port ?? 'SMTP_PORT';
|
|
13
|
-
const port = Number(environment[portKey] ?? 587);
|
|
14
|
-
if (!Number.isInteger(port) || port < 1 || port > 65_535)
|
|
15
|
-
throw new Error(`${portKey} must be a valid TCP port`);
|
|
16
|
-
const userKey = keys.user ?? 'SMTP_USER';
|
|
17
|
-
const passwordKey = keys.password ?? 'SMTP_PASSWORD';
|
|
18
|
-
const user = environment[userKey]?.trim();
|
|
19
|
-
const password = environment[passwordKey];
|
|
20
|
-
if (Boolean(user) !== Boolean(password))
|
|
21
|
-
throw new Error(`${userKey} and ${passwordKey} must be configured together`);
|
|
22
|
-
return {
|
|
23
|
-
from,
|
|
24
|
-
host,
|
|
25
|
-
port,
|
|
26
|
-
secure: environment[keys.secure ?? 'SMTP_SECURE']?.trim().toLowerCase() === 'true',
|
|
27
|
-
...(user && password ? { user, password } : {}),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export function createSmtpDelivery(config) {
|
|
31
|
-
const timeout = config.timeoutMs;
|
|
32
|
-
const options = {
|
|
33
|
-
host: config.host,
|
|
34
|
-
port: config.port,
|
|
35
|
-
secure: config.secure,
|
|
36
|
-
servername: config.servername,
|
|
37
|
-
auth: config.user ? { user: config.user, pass: config.password } : undefined,
|
|
38
|
-
...(timeout === undefined ? {} : { connectionTimeout: timeout, greetingTimeout: timeout, socketTimeout: timeout }),
|
|
39
|
-
};
|
|
40
|
-
if (timeout === undefined) {
|
|
41
|
-
const transport = createTransport(options);
|
|
42
|
-
return smtpDelivery(config.from, async (work) => void (await work(transport)));
|
|
43
|
-
}
|
|
44
|
-
return smtpDelivery(config.from, async (work) => {
|
|
45
|
-
// nodemailer cannot abort an exchange, so each one gets its own socket for the deadline to destroy.
|
|
46
|
-
const socket = new net.Socket();
|
|
47
|
-
await withinDeadline(work(createTransport({ ...options, socket })), timeout, () => {
|
|
48
|
-
socket.destroy();
|
|
49
|
-
// Connecting revives a destroyed socket, so one the deadline beat to connecting closes as soon as it opens.
|
|
50
|
-
socket.once('connect', () => socket.destroy());
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function smtpDelivery(from, exchange) {
|
|
55
|
-
return {
|
|
56
|
-
send: ({ fromName, ...message }) => exchange((transport) => transport.sendMail({ from: fromName ? { name: fromName, address: senderAddress(from) } : from, ...message })),
|
|
57
|
-
verify: () => exchange((transport) => transport.verify()),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
// A server that trickles bytes keeps each socket wait short of its timeout, so the whole exchange needs its own deadline.
|
|
61
|
-
async function withinDeadline(work, timeoutMs, abort) {
|
|
62
|
-
let timer;
|
|
63
|
-
const deadline = new Promise((_resolve, reject) => {
|
|
64
|
-
timer = setTimeout(() => {
|
|
65
|
-
abort();
|
|
66
|
-
reject(new Error(`SMTP server did not finish within ${timeoutMs} ms`));
|
|
67
|
-
}, timeoutMs);
|
|
68
|
-
});
|
|
69
|
-
try {
|
|
70
|
-
await Promise.race([work, deadline]);
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function senderAddress(from) {
|
|
77
|
-
return /<([^<>]+)>\s*$/.exec(from)?.[1] ?? from;
|
|
78
|
-
}
|
|
79
|
-
export function standardAuthEmails(delivery, options) {
|
|
80
|
-
const expiry = 'This link expires in one hour.';
|
|
81
|
-
const send = (subject, label) => async ({ user, url }) => delivery.send({
|
|
82
|
-
to: user.email,
|
|
83
|
-
subject,
|
|
84
|
-
text: `${subject} using this link: ${url}\n\n${expiry}`,
|
|
85
|
-
html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href="${escapeHtml(url)}">${label}</a></p><p>${expiry}</p>`,
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),
|
|
89
|
-
sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function escapeHtml(value) {
|
|
93
|
-
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=index.js.map
|
package/dist/email/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAA;AAiD9D,MAAM,UAAU,yBAAyB,CACvC,WAAW,GAAsB,OAAO,CAAC,GAAG,EAC5C,IAAI,GAA2B,EAAE;IAEjC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,CAAA;IAC1D,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,CAAA;IAC3D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,6BAA6B,CAAC,CAAA;IACpF,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,YAAY,6BAA6B,CAAC,CAAA;IAErF,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,CAAA;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAA;IA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I,EAAE,GAAG,OAAO,qBAAqB,GAAG,OAAO,MAAM,EAAE;QACvD,IAAI,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,yCAAyC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,cAAc,MAAM,MAAM;KAC5H,CAAC,CAAA;IACN,OAAO;QACL,iBAAiB,EAAE,IAAI,CAAC,cAAc,OAAO,CAAC,WAAW,WAAW,EAAE,gBAAgB,CAAC;QACvF,qBAAqB,EAAE,IAAI,CAAC,eAAe,OAAO,CAAC,WAAW,gBAAgB,EAAE,sBAAsB,CAAC;KACxG,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import net from 'node:net'\nimport { createTransport, type Transporter } from 'nodemailer'\n\n/** `cid` lets the HTML body reference the attachment inline as `cid:<value>`. */\nexport type EmailAttachment = { filename: string; content: Buffer; contentType: string; cid?: string }\n\nexport type EmailMessage = {\n to: string\n subject: string\n text: string\n html?: string\n attachments?: EmailAttachment[]\n /** Replaces the display name of the configured sender; the address stays the configured one so SPF and DKIM still pass. */\n fromName?: string\n replyTo?: string\n}\n\nexport type SmtpConfig = {\n from: string\n host: string\n port: number\n secure: boolean\n user?: string\n password?: string\n /** The name TLS presents and verifies when `host` is an address the application already resolved. */\n servername?: string\n /** Fails and disconnects a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */\n timeoutMs?: number\n}\n\nexport type SmtpEnvironmentOptions = {\n host?: string\n port?: string\n secure?: string\n user?: string\n password?: string\n from?: string\n}\n\nexport type EmailDelivery = {\n send(message: EmailMessage): Promise<void>\n verify(): Promise<void>\n}\n\nexport type AuthEmailInput<User extends { email: string } = { email: string }> = {\n user: User\n url: string\n token: string\n}\n\nexport function smtpConfigFromEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n keys: SmtpEnvironmentOptions = {},\n): SmtpConfig | undefined {\n const host = environment[keys.host ?? 'SMTP_HOST']?.trim()\n const from = environment[keys.from ?? 'EMAIL_FROM']?.trim()\n if (!host && !from) return undefined\n if (!host) throw new Error(`${keys.host ?? 'SMTP_HOST'} is required for SMTP email`)\n if (!from) throw new Error(`${keys.from ?? 'EMAIL_FROM'} is required for SMTP email`)\n\n const portKey = keys.port ?? 'SMTP_PORT'\n const port = Number(environment[portKey] ?? 587)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(`${portKey} must be a valid TCP port`)\n\n const userKey = keys.user ?? 'SMTP_USER'\n const passwordKey = keys.password ?? 'SMTP_PASSWORD'\n const user = environment[userKey]?.trim()\n const password = environment[passwordKey]\n if (Boolean(user) !== Boolean(password)) throw new Error(`${userKey} and ${passwordKey} must be configured together`)\n\n return {\n from,\n host,\n port,\n secure: environment[keys.secure ?? 'SMTP_SECURE']?.trim().toLowerCase() === 'true',\n ...(user && password ? { user, password } : {}),\n }\n}\n\nexport function createSmtpDelivery(config: SmtpConfig): EmailDelivery {\n const timeout = config.timeoutMs\n const options = {\n host: config.host,\n port: config.port,\n secure: config.secure,\n servername: config.servername,\n auth: config.user ? { user: config.user, pass: config.password } : undefined,\n ...(timeout === undefined ? {} : { connectionTimeout: timeout, greetingTimeout: timeout, socketTimeout: timeout }),\n }\n if (timeout === undefined) {\n const transport = createTransport(options)\n return smtpDelivery(config.from, async (work) => void (await work(transport)))\n }\n return smtpDelivery(config.from, async (work) => {\n // nodemailer cannot abort an exchange, so each one gets its own socket for the deadline to destroy.\n const socket = new net.Socket()\n await withinDeadline(work(createTransport({ ...options, socket })), timeout, () => {\n socket.destroy()\n // Connecting revives a destroyed socket, so one the deadline beat to connecting closes as soon as it opens.\n socket.once('connect', () => socket.destroy())\n })\n })\n}\n\nfunction smtpDelivery(from: string, exchange: (work: (transport: Transporter) => Promise<unknown>) => Promise<void>): EmailDelivery {\n return {\n send: ({ fromName, ...message }) =>\n exchange((transport) => transport.sendMail({ from: fromName ? { name: fromName, address: senderAddress(from) } : from, ...message })),\n verify: () => exchange((transport) => transport.verify()),\n }\n}\n\n// A server that trickles bytes keeps each socket wait short of its timeout, so the whole exchange needs its own deadline.\nasync function withinDeadline(work: Promise<unknown>, timeoutMs: number, abort: () => void) {\n let timer: ReturnType<typeof setTimeout> | undefined\n const deadline = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n abort()\n reject(new Error(`SMTP server did not finish within ${timeoutMs} ms`))\n }, timeoutMs)\n })\n try {\n await Promise.race([work, deadline])\n } finally {\n clearTimeout(timer)\n }\n}\n\nfunction senderAddress(from: string) {\n return /<([^<>]+)>\\s*$/.exec(from)?.[1] ?? from\n}\n\nexport type StandardAuthEmailOptions = { productName: string }\n\nexport function standardAuthEmails<User extends { email: string } = { email: string }>(\n delivery: EmailDelivery,\n options: StandardAuthEmailOptions,\n) {\n const expiry = 'This link expires in one hour.'\n const send =\n (subject: string, label: string) =>\n async ({ user, url }: AuthEmailInput<User>) =>\n delivery.send({\n to: user.email,\n subject,\n text: `${subject} using this link: ${url}\\n\\n${expiry}`,\n html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href=\"${escapeHtml(url)}\">${label}</a></p><p>${expiry}</p>`,\n })\n return {\n sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),\n sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),\n }\n}\n\nfunction escapeHtml(value: string) {\n return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\"', '"')\n}\n"]}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Integration } from './model.js';
|
|
2
|
-
export declare const tanstackQuery: Integration;
|
|
3
|
-
export declare const betterAuth: Integration;
|
|
4
|
-
export declare const tanstackStart: Integration;
|
|
5
|
-
export declare const sqlite: Integration;
|
|
6
|
-
export declare const postgres: Integration;
|
|
7
|
-
export declare const libsql: Integration;
|
|
8
|
-
export declare const email: Integration;
|
|
9
|
-
export declare const uploads: Integration;
|
|
10
|
-
export declare const realtime: Integration;
|
|
11
|
-
export declare const posthog: {
|
|
12
|
-
readonly browser: Integration;
|
|
13
|
-
readonly react: Integration;
|
|
14
|
-
readonly server: Integration;
|
|
15
|
-
readonly build: Integration;
|
|
16
|
-
};
|
|
17
|
-
export declare const tailwind: {
|
|
18
|
-
readonly name: string;
|
|
19
|
-
readonly packages?: Readonly<Record<string, string>>;
|
|
20
|
-
readonly devPackages?: Readonly<Record<string, string>>;
|
|
21
|
-
readonly includes?: readonly Integration[];
|
|
22
|
-
readonly commands?: Readonly<Record<string, {
|
|
23
|
-
readonly package: string;
|
|
24
|
-
readonly bin: string;
|
|
25
|
-
readonly args?: readonly string[];
|
|
26
|
-
}>>;
|
|
27
|
-
readonly presets?: {
|
|
28
|
-
readonly typescript?: string;
|
|
29
|
-
readonly oxlint?: readonly string[];
|
|
30
|
-
readonly vite?: readonly string[];
|
|
31
|
-
};
|
|
32
|
-
readonly animations: Integration;
|
|
33
|
-
};
|
|
34
|
-
export declare const nitro: Integration;
|
|
35
|
-
export declare const typescript: Integration & Record<"browser" | "bundler" | "library", Integration>;
|
|
36
|
-
export declare const oxlint: Integration & Record<"domain" | "layers", Integration>;
|
|
37
|
-
export declare const oxfmt: Integration;
|
|
38
|
-
export declare const vite: Integration;
|
|
39
|
-
export declare const vitest: Integration;
|
|
40
|
-
export declare const playwright: Integration;
|