@prisma-next/sqlite 0.10.0-dev.9 → 0.11.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/README.md +77 -47
- package/dist/config.d.mts +18 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +36 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract-builder.d.mts +29 -0
- package/dist/contract-builder.d.mts.map +1 -0
- package/dist/contract-builder.mjs +17 -0
- package/dist/contract-builder.mjs.map +1 -0
- package/dist/control.d.mts +11 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +21 -0
- package/dist/control.mjs.map +1 -0
- package/dist/migration.d.mts +1 -0
- package/dist/migration.mjs +2 -0
- package/dist/runtime.d.mts +3 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +18 -0
- package/dist/runtime.mjs.map +1 -1
- package/package.json +25 -15
- package/src/config/define-config.ts +55 -0
- package/src/contract/define-contract.ts +126 -0
- package/src/exports/config.ts +2 -0
- package/src/exports/contract-builder.ts +17 -0
- package/src/exports/control.ts +29 -0
- package/src/exports/migration.ts +1 -0
- package/src/runtime/sqlite.ts +28 -0
package/README.md
CHANGED
|
@@ -1,67 +1,97 @@
|
|
|
1
1
|
# @prisma-next/sqlite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One-package SQLite setup for Prisma Next. Install this single package to get config, runtime, contract authoring, control-plane access, and migration helpers — no reach-ins to internal packages required.
|
|
4
4
|
|
|
5
5
|
## Package Classification
|
|
6
6
|
|
|
7
7
|
- **Domain**: extensions
|
|
8
8
|
- **Layer**: adapters
|
|
9
|
-
- **
|
|
9
|
+
- **Planes**: shared (config, contract-builder), migration (control, migration), runtime (runtime)
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```typescript
|
|
14
|
+
// prisma-next.config.ts
|
|
15
|
+
import { defineConfig } from '@prisma-next/sqlite/config';
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
contract: './prisma/contract.prisma',
|
|
19
|
+
db: { connection: 'path/to/app.db' },
|
|
20
|
+
});
|
|
21
|
+
```
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
```typescript
|
|
24
|
+
// prisma/contract.ts
|
|
25
|
+
import { defineContract, field, model } from '@prisma-next/sqlite/contract-builder';
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
export default defineContract({
|
|
28
|
+
models: {
|
|
29
|
+
User: model('User', { fields: { id: field.id.uuidv4() } }),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
- Build typed SQL surface from the execution context via `sql-query-builder-new`
|
|
27
|
-
- Build ORM surface from the execution context
|
|
28
|
-
- Normalize runtime binding input (file path or `:memory:`)
|
|
29
|
-
- Lazily instantiate runtime resources on first `db.runtime()` or `db.connect(...)` call
|
|
30
|
-
- Connect the internal SQLite driver through `db.connect(...)` or from initial binding options
|
|
31
|
-
- Memoize runtime so repeated `db.runtime()` calls return one instance
|
|
34
|
+
## Exports
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
### `@prisma-next/sqlite/config`
|
|
37
|
+
|
|
38
|
+
Simplified `defineConfig` that pre-wires all SQLite internals (family, target, adapter, driver, contract providers). Accepts `contract`, `db.connection`, `extensions`, and `migrations.dir`.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { defineConfig } from '@prisma-next/sqlite/config';
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
contract: './prisma/contract.prisma',
|
|
45
|
+
db: { connection: 'path/to/app.db' },
|
|
46
|
+
migrations: { dir: 'migrations/app' },
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### `@prisma-next/sqlite/contract-builder`
|
|
51
|
+
|
|
52
|
+
TypeScript contract authoring DSL (`defineContract`, `field`, `model`, `rel`, …). The `defineContract` facade pre-binds `family` and `target` — callers do not pass those fields.
|
|
34
53
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
- **`@prisma-next/sql-contract`** for contract types (contract validation flows through the `ContractSerializer` SPI on the SQL family target descriptor; the `sqlite<Contract>(...)` facade wraps it)
|
|
44
|
-
|
|
45
|
-
## Architecture
|
|
46
|
-
|
|
47
|
-
```mermaid
|
|
48
|
-
flowchart TD
|
|
49
|
-
App[App Code] --> Client["sqlite(...)"]
|
|
50
|
-
Client --> Static["Roots: sql orm context stack"]
|
|
51
|
-
Client --> Lazy["runtime()"]
|
|
52
|
-
|
|
53
|
-
Lazy --> Instantiate[instantiateExecutionStack]
|
|
54
|
-
Lazy --> Bind["Resolve binding: path or :memory:"]
|
|
55
|
-
Bind --> DB["DatabaseSync via node:sqlite"]
|
|
56
|
-
Lazy --> Runtime[createRuntime]
|
|
57
|
-
|
|
58
|
-
Runtime --> Target["@prisma-next/target-sqlite"]
|
|
59
|
-
Runtime --> Adapter["@prisma-next/adapter-sqlite"]
|
|
60
|
-
Runtime --> Driver["@prisma-next/driver-sqlite"]
|
|
61
|
-
Runtime --> SqlRuntime["@prisma-next/sql-runtime"]
|
|
62
|
-
Runtime --> ExecPlane["@prisma-next/framework-components/execution"]
|
|
54
|
+
```typescript
|
|
55
|
+
import { defineContract, field, model } from '@prisma-next/sqlite/contract-builder';
|
|
56
|
+
|
|
57
|
+
export default defineContract({
|
|
58
|
+
models: {
|
|
59
|
+
User: model('User', { fields: { id: field.id.uuidv4() } }),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
63
62
|
```
|
|
64
63
|
|
|
64
|
+
### `@prisma-next/sqlite/control`
|
|
65
|
+
|
|
66
|
+
Control-plane client factory. Collapses the family + target + adapter + driver wiring into a single call.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { createSqliteControlClient } from '@prisma-next/sqlite/control';
|
|
70
|
+
|
|
71
|
+
const control = createSqliteControlClient({
|
|
72
|
+
connection: 'path/to/app.db',
|
|
73
|
+
});
|
|
74
|
+
await control.dbUpdate({ migrations: { dir: 'migrations/app' } });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `@prisma-next/sqlite/migration`
|
|
78
|
+
|
|
79
|
+
Re-exports all migration operation helpers from `@prisma-next/target-sqlite/migration` (`Migration`, `MigrationCLI`, `createTable`, `addColumn`, `dropTable`, `createIndex`, `dropIndex`, `dropColumn`, `recreateTable`, `dataTransform`, `placeholder`, `rawSql`).
|
|
80
|
+
|
|
81
|
+
### `@prisma-next/sqlite/runtime`
|
|
82
|
+
|
|
83
|
+
Composes the SQLite execution stack and returns typed query roots (`db.sql`, `db.orm`, `db.context`, `db.stack`).
|
|
84
|
+
|
|
85
|
+
## Dependencies
|
|
86
|
+
|
|
87
|
+
This package bundles all the transitive dependencies needed for a SQLite Prisma Next project:
|
|
88
|
+
|
|
89
|
+
- `@prisma-next/target-sqlite` (target descriptor + migration surface)
|
|
90
|
+
- `@prisma-next/adapter-sqlite` (adapter descriptor)
|
|
91
|
+
- `@prisma-next/driver-sqlite` (driver descriptor)
|
|
92
|
+
- `@prisma-next/sql-contract-ts` (TypeScript contract authoring)
|
|
93
|
+
- `@prisma-next/sql-contract` (contract type definitions)
|
|
94
|
+
|
|
65
95
|
## Related Docs
|
|
66
96
|
|
|
67
97
|
- Architecture: `docs/Architecture Overview.md`
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PrismaNextConfig } from "@prisma-next/config/config-types";
|
|
2
|
+
import { ControlExtensionDescriptor } from "@prisma-next/framework-components/control";
|
|
3
|
+
|
|
4
|
+
//#region src/config/define-config.d.ts
|
|
5
|
+
interface SqliteConfigOptions {
|
|
6
|
+
readonly contract: string;
|
|
7
|
+
readonly db?: {
|
|
8
|
+
readonly connection?: string;
|
|
9
|
+
};
|
|
10
|
+
readonly extensions?: readonly ControlExtensionDescriptor<'sql', 'sqlite'>[];
|
|
11
|
+
readonly migrations?: {
|
|
12
|
+
readonly dir?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
declare function defineConfig(options: SqliteConfigOptions): PrismaNextConfig<'sql', 'sqlite'>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type SqliteConfigOptions, defineConfig };
|
|
18
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config/define-config.ts"],"mappings":";;;;UAYiB,mBAAA;EAAA,SACN,QAAA;EAAA,SACA,EAAA;IAAA,SACE,UAAA;EAAA;EAAA,SAEF,UAAA,YAAsB,0BAAA;EAAA,SACtB,UAAA;IAAA,SACE,GAAA;EAAA;AAAA;AAAA,iBAYG,YAAA,CAAa,OAAA,EAAS,mBAAA,GAAsB,gBAAA"}
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import sqliteAdapter from "@prisma-next/adapter-sqlite/control";
|
|
2
|
+
import { defineConfig as defineConfig$1 } from "@prisma-next/config/config-types";
|
|
3
|
+
import sqliteDriver from "@prisma-next/driver-sqlite/control";
|
|
4
|
+
import sql from "@prisma-next/family-sql/control";
|
|
5
|
+
import { prismaContract } from "@prisma-next/sql-contract-psl/provider";
|
|
6
|
+
import { typescriptContractFromPath } from "@prisma-next/sql-contract-ts/config-types";
|
|
7
|
+
import sqlite from "@prisma-next/target-sqlite/control";
|
|
8
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
9
|
+
import { extname } from "pathe";
|
|
10
|
+
//#region src/config/define-config.ts
|
|
11
|
+
function deriveOutputPath(contractPath) {
|
|
12
|
+
const ext = extname(contractPath);
|
|
13
|
+
if (ext.length === 0) return `${contractPath}.json`;
|
|
14
|
+
return `${contractPath.slice(0, -ext.length)}.json`;
|
|
15
|
+
}
|
|
16
|
+
function defineConfig(options) {
|
|
17
|
+
const extensions = options.extensions ?? [];
|
|
18
|
+
const output = deriveOutputPath(options.contract);
|
|
19
|
+
return defineConfig$1({
|
|
20
|
+
family: sql,
|
|
21
|
+
target: sqlite,
|
|
22
|
+
adapter: sqliteAdapter,
|
|
23
|
+
driver: sqliteDriver,
|
|
24
|
+
extensionPacks: extensions,
|
|
25
|
+
contract: extname(options.contract) === ".ts" ? typescriptContractFromPath(options.contract, output) : prismaContract(options.contract, {
|
|
26
|
+
output,
|
|
27
|
+
target: sqlite
|
|
28
|
+
}),
|
|
29
|
+
...ifDefined("db", options.db),
|
|
30
|
+
...ifDefined("migrations", options.migrations)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { defineConfig };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.mjs","names":["coreDefineConfig"],"sources":["../src/config/define-config.ts"],"sourcesContent":["import sqliteAdapter from '@prisma-next/adapter-sqlite/control';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { defineConfig as coreDefineConfig } from '@prisma-next/config/config-types';\nimport sqliteDriver from '@prisma-next/driver-sqlite/control';\nimport sql from '@prisma-next/family-sql/control';\nimport type { ControlExtensionDescriptor } from '@prisma-next/framework-components/control';\nimport { prismaContract } from '@prisma-next/sql-contract-psl/provider';\nimport { typescriptContractFromPath } from '@prisma-next/sql-contract-ts/config-types';\nimport sqlite from '@prisma-next/target-sqlite/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { extname } from 'pathe';\n\nexport interface SqliteConfigOptions {\n readonly contract: string;\n readonly db?: {\n readonly connection?: string;\n };\n readonly extensions?: readonly ControlExtensionDescriptor<'sql', 'sqlite'>[];\n readonly migrations?: {\n readonly dir?: string;\n };\n}\n\nfunction deriveOutputPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) {\n return `${contractPath}.json`;\n }\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport function defineConfig(options: SqliteConfigOptions): PrismaNextConfig<'sql', 'sqlite'> {\n const extensions = options.extensions ?? [];\n const output = deriveOutputPath(options.contract);\n const ext = extname(options.contract);\n\n const contractConfig =\n ext === '.ts'\n ? typescriptContractFromPath(options.contract, output)\n : prismaContract(options.contract, {\n output,\n target: sqlite,\n });\n\n return coreDefineConfig({\n family: sql,\n target: sqlite,\n adapter: sqliteAdapter,\n driver: sqliteDriver,\n extensionPacks: extensions,\n contract: contractConfig,\n ...ifDefined('db', options.db),\n ...ifDefined('migrations', options.migrations),\n });\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAS,iBAAiB,cAA8B;CACtD,MAAM,MAAM,QAAQ,aAAa;CACjC,IAAI,IAAI,WAAW,GACjB,OAAO,GAAG,aAAa;CAEzB,OAAO,GAAG,aAAa,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC;;AAG/C,SAAgB,aAAa,SAAiE;CAC5F,MAAM,aAAa,QAAQ,cAAc,EAAE;CAC3C,MAAM,SAAS,iBAAiB,QAAQ,SAAS;CAWjD,OAAOA,eAAiB;EACtB,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,gBAAgB;EAChB,UAhBU,QAAQ,QAAQ,SAGvB,KAAK,QACJ,2BAA2B,QAAQ,UAAU,OAAO,GACpD,eAAe,QAAQ,UAAU;GAC/B;GACA,QAAQ;GACT,CAAC;EASN,GAAG,UAAU,MAAM,QAAQ,GAAG;EAC9B,GAAG,UAAU,cAAc,QAAQ,WAAW;EAC/C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComposedAuthoringHelpers, ComposedAuthoringHelpers as ComposedAuthoringHelpers$1, ContractDefinition, ContractInput, ContractInput as ContractInput$1, ContractModelBuilder, FieldNode, ForeignKeyNode, IndexNode, ModelLike, ModelLike as ModelLike$1, ModelNode, PrimaryKeyNode, RelationNode, ScalarFieldBuilder, UniqueConstraintNode, defineContract as defineContract$1, field, model, rel } from "@prisma-next/sql-contract-ts/contract-builder";
|
|
2
|
+
import sqlFamilyPack from "@prisma-next/family-sql/pack";
|
|
3
|
+
import sqlitePack from "@prisma-next/target-sqlite/pack";
|
|
4
|
+
import { ExtensionPackRef } from "@prisma-next/framework-components/components";
|
|
5
|
+
import { StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
6
|
+
|
|
7
|
+
//#region src/contract/define-contract.d.ts
|
|
8
|
+
type SqlFamily = typeof sqlFamilyPack;
|
|
9
|
+
type SqlitePack = typeof sqlitePack;
|
|
10
|
+
type TypesConstraint = Record<string, StorageTypeInstance>;
|
|
11
|
+
type ModelsConstraint = Record<string, ModelLike$1>;
|
|
12
|
+
type SqliteResult<Types extends TypesConstraint, Models extends ModelsConstraint, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined> = Omit<ReturnType<typeof defineContract$1<SqlFamily, SqlitePack, Types, Models, ExtensionPacks, Capabilities>>, 'target' | 'targetFamily'> & {
|
|
13
|
+
readonly target: SqlitePack['targetId'];
|
|
14
|
+
readonly targetFamily: SqlFamily['familyId'];
|
|
15
|
+
};
|
|
16
|
+
type SqliteBaseScaffold<ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined> = Omit<ContractInput$1<SqlFamily, SqlitePack, Record<never, never>, Record<never, never>, ExtensionPacks, Capabilities>, 'family' | 'target' | 'types' | 'models'>;
|
|
17
|
+
type SqliteDefinition<Types extends TypesConstraint, Models extends ModelsConstraint, ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined> = SqliteBaseScaffold<ExtensionPacks, Capabilities> & {
|
|
18
|
+
readonly types?: Types;
|
|
19
|
+
readonly models?: Models;
|
|
20
|
+
};
|
|
21
|
+
type SqliteScaffold<ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined> = SqliteBaseScaffold<ExtensionPacks, Capabilities>;
|
|
22
|
+
declare function defineContract<const Types extends TypesConstraint = Record<never, never>, const Models extends ModelsConstraint = Record<never, never>, const ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined>(definition: SqliteDefinition<Types, Models, ExtensionPacks, Capabilities>): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;
|
|
23
|
+
declare function defineContract<const Types extends TypesConstraint = Record<never, never>, const Models extends ModelsConstraint = Record<never, never>, const ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined = undefined, const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined>(scaffold: SqliteScaffold<ExtensionPacks, Capabilities>, factory: (helpers: ComposedAuthoringHelpers$1<SqlFamily, SqlitePack, ExtensionPacks>) => {
|
|
24
|
+
readonly types?: Types;
|
|
25
|
+
readonly models?: Models;
|
|
26
|
+
}): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type ComposedAuthoringHelpers, type ContractDefinition, type ContractInput, type ContractModelBuilder, type FieldNode, type ForeignKeyNode, type IndexNode, type ModelLike, type ModelNode, type PrimaryKeyNode, type RelationNode, type ScalarFieldBuilder, type UniqueConstraintNode, defineContract, field, model, rel };
|
|
29
|
+
//# sourceMappingURL=contract-builder.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-builder.d.mts","names":[],"sources":["../src/contract/define-contract.ts"],"mappings":";;;;;;;KAWK,SAAA,UAAmB,aAAA;AAAA,KACnB,UAAA,UAAoB,UAAA;AAAA,KAEpB,eAAA,GAAkB,MAAA,SAAe,mBAAA;AAAA,KACjC,gBAAA,GAAmB,MAAA,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OAAA,GAAU,OAAA,EAAS,0BAAA,CAAyB,SAAA,EAAW,UAAA,EAAY,cAAA;EAAA,SACxD,KAAA,GAAQ,KAAA;EAAA,SACR,MAAA,GAAS,MAAA;AAAA,IAEnB,YAAA,CAAa,KAAA,EAAO,MAAA,EAAQ,cAAA,EAAgB,YAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineContract as defineContract$1, field, model, rel } from "@prisma-next/sql-contract-ts/contract-builder";
|
|
2
|
+
import sqlFamilyPack from "@prisma-next/family-sql/pack";
|
|
3
|
+
import sqlitePack from "@prisma-next/target-sqlite/pack";
|
|
4
|
+
//#region src/contract/define-contract.ts
|
|
5
|
+
function defineContract(scaffold, factory) {
|
|
6
|
+
const full = {
|
|
7
|
+
...scaffold,
|
|
8
|
+
family: sqlFamilyPack,
|
|
9
|
+
target: sqlitePack
|
|
10
|
+
};
|
|
11
|
+
if (factory !== void 0) return defineContract$1(full, factory);
|
|
12
|
+
return defineContract$1(full);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { defineContract, field, model, rel };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=contract-builder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-builder.mjs","names":["baseDefineContract"],"sources":["../src/contract/define-contract.ts"],"sourcesContent":["import sqlFamilyPack from '@prisma-next/family-sql/pack';\nimport type { ExtensionPackRef } from '@prisma-next/framework-components/components';\nimport type { StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport type {\n ComposedAuthoringHelpers,\n ContractInput,\n ModelLike,\n} from '@prisma-next/sql-contract-ts/contract-builder';\nimport { defineContract as baseDefineContract } from '@prisma-next/sql-contract-ts/contract-builder';\nimport sqlitePack from '@prisma-next/target-sqlite/pack';\n\ntype SqlFamily = typeof sqlFamilyPack;\ntype SqlitePack = typeof sqlitePack;\n\ntype TypesConstraint = Record<string, StorageTypeInstance>;\ntype ModelsConstraint = Record<string, ModelLike>;\n\n// Return type threaded with all inferred type params.\n// We override target/targetFamily via intersection to preserve the literal values\n// ('sqlite', 'sql') even when TypeScript defers conditional-type evaluation on\n// unresolved generic params.\ntype SqliteResult<\n Types extends TypesConstraint,\n Models extends ModelsConstraint,\n ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,\n Capabilities extends Record<string, Record<string, boolean>> | undefined,\n> = Omit<\n ReturnType<\n typeof baseDefineContract<SqlFamily, SqlitePack, Types, Models, ExtensionPacks, Capabilities>\n >,\n 'target' | 'targetFamily'\n> & {\n readonly target: SqlitePack['targetId'];\n readonly targetFamily: SqlFamily['familyId'];\n};\n\n// Scaffold that carries all ContractInput fields EXCEPT family, target, types, models.\n// Built from ContractInput with concrete Record<never, never> defaults to avoid\n// the ContractInput Models constraint (which requires ContractModelBuilder, not ModelLike).\ntype SqliteBaseScaffold<\n ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,\n Capabilities extends Record<string, Record<string, boolean>> | undefined,\n> = Omit<\n ContractInput<\n SqlFamily,\n SqlitePack,\n Record<never, never>,\n Record<never, never>,\n ExtensionPacks,\n Capabilities\n >,\n 'family' | 'target' | 'types' | 'models'\n>;\n\n// Definition form: inline types + models (uses ModelLike for models, not ContractModelBuilder)\ntype SqliteDefinition<\n Types extends TypesConstraint,\n Models extends ModelsConstraint,\n ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,\n Capabilities extends Record<string, Record<string, boolean>> | undefined,\n> = SqliteBaseScaffold<ExtensionPacks, Capabilities> & {\n readonly types?: Types;\n readonly models?: Models;\n};\n\n// Factory form: scaffold without types/models (factory provides them)\ntype SqliteScaffold<\n ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,\n Capabilities extends Record<string, Record<string, boolean>> | undefined,\n> = SqliteBaseScaffold<ExtensionPacks, Capabilities>;\n\n// Overload 1: definition form (models/types inline in scaffold)\nexport function defineContract<\n const Types extends TypesConstraint = Record<never, never>,\n const Models extends ModelsConstraint = Record<never, never>,\n const ExtensionPacks extends\n | Record<string, ExtensionPackRef<'sql', string>>\n | undefined = undefined,\n const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,\n>(\n definition: SqliteDefinition<Types, Models, ExtensionPacks, Capabilities>,\n): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;\n\n// Overload 2: factory form (scaffold without models/types; factory provides them)\nexport function defineContract<\n const Types extends TypesConstraint = Record<never, never>,\n const Models extends ModelsConstraint = Record<never, never>,\n const ExtensionPacks extends\n | Record<string, ExtensionPackRef<'sql', string>>\n | undefined = undefined,\n const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,\n>(\n scaffold: SqliteScaffold<ExtensionPacks, Capabilities>,\n factory: (helpers: ComposedAuthoringHelpers<SqlFamily, SqlitePack, ExtensionPacks>) => {\n readonly types?: Types;\n readonly models?: Models;\n },\n): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;\n\n// Implementation — the runtime type is richer than the wide impl signature;\n// as unknown is safe because every declared overload produces a SqliteResult.\nexport function defineContract(\n scaffold: Omit<ContractInput, 'family' | 'target'>,\n factory?: (helpers: ComposedAuthoringHelpers<SqlFamily, SqlitePack, undefined>) => {\n readonly types?: TypesConstraint;\n readonly models?: ModelsConstraint;\n },\n): SqliteResult<TypesConstraint, ModelsConstraint, undefined, undefined> {\n const full = {\n ...scaffold,\n family: sqlFamilyPack,\n target: sqlitePack,\n } as ContractInput;\n if (factory !== undefined) {\n return baseDefineContract(\n full,\n factory as Parameters<typeof baseDefineContract>[1],\n ) as unknown as SqliteResult<TypesConstraint, ModelsConstraint, undefined, undefined>;\n }\n return baseDefineContract(full) as unknown as SqliteResult<\n TypesConstraint,\n ModelsConstraint,\n undefined,\n undefined\n >;\n}\n"],"mappings":";;;;AAqGA,SAAgB,eACd,UACA,SAIuE;CACvE,MAAM,OAAO;EACX,GAAG;EACH,QAAQ;EACR,QAAQ;EACT;CACD,IAAI,YAAY,KAAA,GACd,OAAOA,iBACL,MACA,QACD;CAEH,OAAOA,iBAAmB,KAAK"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ControlClient, ControlClientOptions } from "@prisma-next/cli/control-api";
|
|
2
|
+
|
|
3
|
+
//#region src/exports/control.d.ts
|
|
4
|
+
interface SqliteControlClientOptions {
|
|
5
|
+
readonly connection?: string;
|
|
6
|
+
readonly extensionPacks?: ControlClientOptions['extensionPacks'];
|
|
7
|
+
}
|
|
8
|
+
declare function createSqliteControlClient(options?: SqliteControlClientOptions): ControlClient;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type ControlClient, SqliteControlClientOptions, createSqliteControlClient };
|
|
11
|
+
//# sourceMappingURL=control.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"mappings":";;;UAWiB,0BAAA;EAAA,SACN,UAAA;EAAA,SACA,cAAA,GAAiB,oBAAA;AAAA;AAAA,iBAGZ,yBAAA,CAA0B,OAAA,GAAS,0BAAA,GAAkC,aAAA"}
|
package/dist/control.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import sqliteAdapter from "@prisma-next/adapter-sqlite/control";
|
|
2
|
+
import sqliteDriver from "@prisma-next/driver-sqlite/control";
|
|
3
|
+
import sql from "@prisma-next/family-sql/control";
|
|
4
|
+
import sqlite from "@prisma-next/target-sqlite/control";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
import { createControlClient } from "@prisma-next/cli/control-api";
|
|
7
|
+
//#region src/exports/control.ts
|
|
8
|
+
function createSqliteControlClient(options = {}) {
|
|
9
|
+
return createControlClient({
|
|
10
|
+
family: sql,
|
|
11
|
+
target: sqlite,
|
|
12
|
+
adapter: sqliteAdapter,
|
|
13
|
+
driver: sqliteDriver,
|
|
14
|
+
...ifDefined("connection", options.connection),
|
|
15
|
+
...ifDefined("extensionPacks", options.extensionPacks)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createSqliteControlClient };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=control.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control.mjs","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":["import sqliteAdapter from '@prisma-next/adapter-sqlite/control';\nimport {\n type ControlClient,\n type ControlClientOptions,\n createControlClient,\n} from '@prisma-next/cli/control-api';\nimport sqliteDriver from '@prisma-next/driver-sqlite/control';\nimport sql from '@prisma-next/family-sql/control';\nimport sqlite from '@prisma-next/target-sqlite/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nexport interface SqliteControlClientOptions {\n readonly connection?: string;\n readonly extensionPacks?: ControlClientOptions['extensionPacks'];\n}\n\nexport function createSqliteControlClient(options: SqliteControlClientOptions = {}): ControlClient {\n const clientOptions: ControlClientOptions = {\n family: sql,\n target: sqlite,\n adapter: sqliteAdapter,\n driver: sqliteDriver,\n ...ifDefined('connection', options.connection),\n ...ifDefined('extensionPacks', options.extensionPacks),\n };\n return createControlClient(clientOptions);\n}\n\nexport type { ControlClient };\n"],"mappings":";;;;;;;AAgBA,SAAgB,0BAA0B,UAAsC,EAAE,EAAiB;CASjG,OAAO,oBAAoB;EAPzB,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,GAAG,UAAU,cAAc,QAAQ,WAAW;EAC9C,GAAG,UAAU,kBAAkB,QAAQ,eAAe;EAEhB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@prisma-next/target-sqlite/migration";
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { orm } from "@prisma-next/sql-orm-client";
|
|
2
2
|
import { BindSiteParams, Declaration, ExecutionContext, ParamsFromDeclaration, PreparedStatement, Runtime, RuntimeVerifyOptions, SqlExecutionStackWithDriver, SqlMiddleware, SqlRuntimeExtensionDescriptor } from "@prisma-next/sql-runtime";
|
|
3
|
+
import { ExtractCodecTypes, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
3
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
5
|
import { Db } from "@prisma-next/sql-builder/types";
|
|
5
|
-
import { ExtractCodecTypes, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
6
6
|
import { CodecTypesBase } from "@prisma-next/sql-relational-core/expression";
|
|
7
7
|
import { SqlQueryPlan } from "@prisma-next/sql-relational-core/plan";
|
|
8
8
|
|
|
@@ -24,6 +24,8 @@ interface SqliteClient<TContract extends Contract<SqlStorage>> {
|
|
|
24
24
|
}): Promise<Runtime>;
|
|
25
25
|
runtime(): Runtime;
|
|
26
26
|
prepare<D extends Declaration<CT>, Row, CT extends CodecTypesBase = ExtractCodecTypes<TContract> & CodecTypesBase>(declaration: D, callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
27
29
|
}
|
|
28
30
|
interface SqliteOptionsBase {
|
|
29
31
|
readonly extensions?: readonly SqlRuntimeExtensionDescriptor<SqliteTargetId>[];
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/runtime/binding.ts","../src/runtime/sqlite.ts"],"mappings":";;;;;;;;;KAEY,kBAAA;EAAA,SAAgC,IAAA;AAAA;;;KC8BhC,cAAA;AAAA,KACP,SAAA,mBAA4B,QAAA,CAAS,UAAA,KAAe,UAAA,QAAkB,GAAA,CAAW,SAAA;AAAA,UAErE,YAAA,mBAA+B,QAAA,CAAS,UAAA;EAAA,SAC9C,GAAA,EAAK,EAAA,CAAG,SAAA;EAAA,SACR,GAAA,EAAK,SAAA,CAAU,SAAA;EAAA,SACf,OAAA,EAAS,gBA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O,YAAA,CAAa,GAAA,IACzE,OAAA,CAAQ,iBAAA,CAAkB,qBAAA,CAAsB,CAAA,EAAG,EAAA,GAAK,GAAA;EAC3D,KAAA,IAAS,OAAA;EAAA,CACR,MAAA,CAAO,YAAP,KAAwB,OAAA;AAAA;AAAA,UAGV,iBAAA;EAAA,SACN,UAAA,YAAsB,6BAAA,CAA8B,cAAA;EAAA,SACpD,UAAA,YAAsB,aAAA;EAAA,SACtB,MAAA,GAAS,oBAAA;AAAA;AAAA,KAGR,yBAAA,mBAA4C,QAAA,CAAS,UAAA;EAAA,SACtD,IAAA;AAAA,IACP,iBAAA;EAAA,SACS,QAAA,EAAU,SAAA;EAAA,SACV,YAAA;AAAA;AAAA,KAGD,6BAAA,mBAAgD,QAAA,CAAS,UAAA;EAAA,SAC1D,IAAA;EAAA,SACA,SAAA,GAAY,SAAA;AAAA,IACnB,iBAAA;EAAA,SACS,YAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGD,aAAA,mBAAgC,QAAA,CAAS,UAAA,KACjD,yBAAA,CAA0B,SAAA,IAC1B,6BAAA,CAA8B,SAAA;AAAA,iBAYV,MAAA,mBAAyB,QAAA,CAAS,UAAA,EAAA,CACxD,OAAA,EAAS,yBAAA,CAA0B,SAAA,IAClC,YAAA,CAAa,SAAA;AAAA,iBACQ,MAAA,mBAAyB,QAAA,CAAS,UAAA,EAAA,CACxD,OAAA,EAAS,6BAAA,CAA8B,SAAA,IACtC,YAAA,CAAa,SAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -44,7 +44,10 @@ function sqlite(options) {
|
|
|
44
44
|
let runtimeDriver;
|
|
45
45
|
let driverConnected = false;
|
|
46
46
|
let connectPromise;
|
|
47
|
+
let closePromise;
|
|
47
48
|
let backgroundConnectError;
|
|
49
|
+
let closed = false;
|
|
50
|
+
let ownedDispose;
|
|
48
51
|
const connectDriver = async (resolvedBinding) => {
|
|
49
52
|
if (driverConnected) return;
|
|
50
53
|
if (!runtimeDriver) throw new Error("SQLite runtime driver missing");
|
|
@@ -59,12 +62,14 @@ function sqlite(options) {
|
|
|
59
62
|
return connectPromise;
|
|
60
63
|
};
|
|
61
64
|
const getRuntime = () => {
|
|
65
|
+
if (closed) throw new Error("SQLite client is closed");
|
|
62
66
|
if (backgroundConnectError !== void 0) throw backgroundConnectError;
|
|
63
67
|
if (runtimeInstance) return runtimeInstance;
|
|
64
68
|
const stackInstance = instantiateExecutionStack(stack);
|
|
65
69
|
const driverDescriptor = stack.driver;
|
|
66
70
|
if (!driverDescriptor) throw new Error("Driver descriptor missing from execution stack");
|
|
67
71
|
const driver = driverDescriptor.create();
|
|
72
|
+
ownedDispose = () => driver.close();
|
|
68
73
|
runtimeDriver = driver;
|
|
69
74
|
if (binding !== void 0) connectDriver(binding).catch(() => void 0);
|
|
70
75
|
runtimeInstance = createRuntime({
|
|
@@ -95,6 +100,7 @@ function sqlite(options) {
|
|
|
95
100
|
context,
|
|
96
101
|
stack,
|
|
97
102
|
async connect(bindingInput) {
|
|
103
|
+
if (closed) throw new Error("SQLite client is closed");
|
|
98
104
|
if (driverConnected || connectPromise) throw new Error("SQLite client already connected");
|
|
99
105
|
backgroundConnectError = void 0;
|
|
100
106
|
if (bindingInput !== void 0) binding = resolveSqliteBinding(bindingInput);
|
|
@@ -109,6 +115,18 @@ function sqlite(options) {
|
|
|
109
115
|
},
|
|
110
116
|
prepare(declaration, callback) {
|
|
111
117
|
return getRuntime().prepare(declaration, (params) => callback(sql$1, params));
|
|
118
|
+
},
|
|
119
|
+
close() {
|
|
120
|
+
if (closePromise) return closePromise;
|
|
121
|
+
closed = true;
|
|
122
|
+
closePromise = (async () => {
|
|
123
|
+
await connectPromise?.catch(() => void 0);
|
|
124
|
+
await ownedDispose?.();
|
|
125
|
+
})();
|
|
126
|
+
return closePromise;
|
|
127
|
+
},
|
|
128
|
+
[Symbol.asyncDispose]() {
|
|
129
|
+
return this.close();
|
|
112
130
|
}
|
|
113
131
|
};
|
|
114
132
|
}
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":["sql","sqlBuilder","ormBuilder"],"sources":["../src/runtime/binding.ts","../src/runtime/sqlite.ts"],"sourcesContent":["import type { SqliteBinding } from '@prisma-next/driver-sqlite/runtime';\n\nexport type SqliteBindingInput = { readonly path: string };\n\nexport function resolveSqliteBinding(input: SqliteBindingInput): SqliteBinding {\n return { kind: 'path', path: input.path };\n}\n\nexport function resolveOptionalSqliteBinding(options: {\n readonly path?: string;\n}): SqliteBinding | undefined {\n if (options.path === undefined) {\n return undefined;\n }\n return { kind: 'path', path: options.path };\n}\n","import sqliteAdapter from '@prisma-next/adapter-sqlite/runtime';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { SqliteBinding } from '@prisma-next/driver-sqlite/runtime';\nimport sqliteDriver from '@prisma-next/driver-sqlite/runtime';\nimport { SqlContractSerializer } from '@prisma-next/family-sql/ir';\nimport { instantiateExecutionStack } from '@prisma-next/framework-components/execution';\nimport { sql as sqlBuilder } from '@prisma-next/sql-builder/runtime';\nimport type { Db } from '@prisma-next/sql-builder/types';\nimport type { ExtractCodecTypes, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { orm as ormBuilder } from '@prisma-next/sql-orm-client';\nimport type { CodecTypesBase } from '@prisma-next/sql-relational-core/expression';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n BindSiteParams,\n Declaration,\n ExecutionContext,\n ParamsFromDeclaration,\n PreparedStatement,\n Runtime,\n RuntimeVerifyOptions,\n SqlExecutionStackWithDriver,\n SqlMiddleware,\n SqlRuntimeExtensionDescriptor,\n} from '@prisma-next/sql-runtime';\nimport {\n createExecutionContext,\n createRuntime,\n createSqlExecutionStack,\n} from '@prisma-next/sql-runtime';\nimport sqliteTarget from '@prisma-next/target-sqlite/runtime';\nimport { resolveOptionalSqliteBinding, resolveSqliteBinding } from './binding';\n\nexport type SqliteTargetId = 'sqlite';\ntype OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof ormBuilder<TContract>>;\n\nexport interface SqliteClient<TContract extends Contract<SqlStorage>> {\n readonly sql: Db<TContract>;\n readonly orm: OrmClient<TContract>;\n readonly context: ExecutionContext<TContract>;\n readonly stack: SqlExecutionStackWithDriver<SqliteTargetId>;\n connect(bindingInput?: { readonly path: string }): Promise<Runtime>;\n runtime(): Runtime;\n prepare<\n D extends Declaration<CT>,\n Row,\n CT extends CodecTypesBase = ExtractCodecTypes<TContract> & CodecTypesBase,\n >(\n declaration: D,\n callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>,\n ): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>>;\n}\n\nexport interface SqliteOptionsBase {\n readonly extensions?: readonly SqlRuntimeExtensionDescriptor<SqliteTargetId>[];\n readonly middleware?: readonly SqlMiddleware[];\n readonly verify?: RuntimeVerifyOptions;\n}\n\nexport type SqliteOptionsWithContract<TContract extends Contract<SqlStorage>> = {\n readonly path?: string;\n} & SqliteOptionsBase & {\n readonly contract: TContract;\n readonly contractJson?: never;\n };\n\nexport type SqliteOptionsWithContractJson<TContract extends Contract<SqlStorage>> = {\n readonly path?: string;\n readonly _contract?: TContract;\n} & SqliteOptionsBase & {\n readonly contractJson: unknown;\n readonly contract?: never;\n };\n\nexport type SqliteOptions<TContract extends Contract<SqlStorage>> =\n | SqliteOptionsWithContract<TContract>\n | SqliteOptionsWithContractJson<TContract>;\n\nfunction resolveContract<TContract extends Contract<SqlStorage>>(\n options: SqliteOptions<TContract>,\n): TContract {\n const contractInput =\n 'contractJson' in options && options.contractJson !== undefined\n ? options.contractJson\n : (options as SqliteOptionsWithContract<TContract>).contract;\n return new SqlContractSerializer().deserializeContract(contractInput) as TContract;\n}\n\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptionsWithContract<TContract>,\n): SqliteClient<TContract>;\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptionsWithContractJson<TContract>,\n): SqliteClient<TContract>;\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptions<TContract>,\n): SqliteClient<TContract> {\n const contract = resolveContract(options);\n let binding = resolveOptionalSqliteBinding(options);\n const stack = createSqlExecutionStack({\n target: sqliteTarget,\n adapter: sqliteAdapter,\n driver: sqliteDriver,\n extensionPacks: options.extensions ?? [],\n });\n\n const context = createExecutionContext({\n contract,\n stack,\n });\n\n const sql: Db<TContract> = sqlBuilder<TContract>({ context });\n let runtimeInstance: Runtime | undefined;\n let runtimeDriver: { connect(binding: unknown): Promise<void> } | undefined;\n let driverConnected = false;\n let connectPromise: Promise<void> | undefined;\n let backgroundConnectError: unknown;\n\n const connectDriver = async (resolvedBinding: SqliteBinding): Promise<void> => {\n if (driverConnected) return;\n if (!runtimeDriver) throw new Error('SQLite runtime driver missing');\n if (connectPromise) return connectPromise;\n connectPromise = runtimeDriver\n .connect(resolvedBinding)\n .then(() => {\n driverConnected = true;\n })\n .catch((err) => {\n backgroundConnectError = err;\n connectPromise = undefined;\n throw err;\n });\n return connectPromise;\n };\n\n const getRuntime = (): Runtime => {\n if (backgroundConnectError !== undefined) {\n throw backgroundConnectError;\n }\n\n if (runtimeInstance) {\n return runtimeInstance;\n }\n\n const stackInstance = instantiateExecutionStack(stack);\n const driverDescriptor = stack.driver;\n if (!driverDescriptor) {\n throw new Error('Driver descriptor missing from execution stack');\n }\n\n const driver = driverDescriptor.create();\n runtimeDriver = driver;\n if (binding !== undefined) {\n void connectDriver(binding).catch(() => undefined);\n }\n\n runtimeInstance = createRuntime({\n stackInstance,\n context,\n driver,\n verify: options.verify ?? { mode: 'onFirstUse', requireMarker: false },\n ...(options.middleware ? { middleware: options.middleware } : {}),\n });\n\n return runtimeInstance;\n };\n\n const orm: OrmClient<TContract> = ormBuilder({\n context,\n runtime: {\n execute(plan) {\n return getRuntime().execute(plan);\n },\n connection() {\n return getRuntime().connection();\n },\n },\n });\n\n return {\n sql,\n orm,\n context,\n stack,\n async connect(bindingInput) {\n if (driverConnected || connectPromise) {\n throw new Error('SQLite client already connected');\n }\n\n backgroundConnectError = undefined;\n\n if (bindingInput !== undefined) {\n binding = resolveSqliteBinding(bindingInput);\n }\n\n if (binding === undefined) {\n throw new Error(\n 'SQLite binding not configured. Pass path to sqlite(...) or call db.connect({ path }).',\n );\n }\n\n const runtime = getRuntime();\n if (driverConnected) {\n return runtime;\n }\n\n await connectDriver(binding);\n return runtime;\n },\n runtime() {\n return getRuntime();\n },\n prepare<\n D extends Declaration<CT>,\n Row,\n CT extends CodecTypesBase = ExtractCodecTypes<TContract> & CodecTypesBase,\n >(\n declaration: D,\n callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>,\n ): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>> {\n return getRuntime().prepare<D, Row, CT>(declaration, (params) => callback(sql, params));\n },\n };\n}\n"],"mappings":";;;;;;;;;AAIA,SAAgB,qBAAqB,OAA0C;CAC7E,OAAO;EAAE,MAAM;EAAQ,MAAM,MAAM;EAAM;;AAG3C,SAAgB,6BAA6B,SAEf;CAC5B,IAAI,QAAQ,SAAS,KAAA,GACnB;CAEF,OAAO;EAAE,MAAM;EAAQ,MAAM,QAAQ;EAAM;;;;AC+D7C,SAAS,gBACP,SACW;CACX,MAAM,gBACJ,kBAAkB,WAAW,QAAQ,iBAAiB,KAAA,IAClD,QAAQ,eACP,QAAiD;CACxD,OAAO,IAAI,uBAAuB,CAAC,oBAAoB,cAAc;;AASvE,SAAwB,OACtB,SACyB;CACzB,MAAM,WAAW,gBAAgB,QAAQ;CACzC,IAAI,UAAU,6BAA6B,QAAQ;CACnD,MAAM,QAAQ,wBAAwB;EACpC,QAAQ;EACR,SAAS;EACT,QAAQ;EACR,gBAAgB,QAAQ,cAAc,EAAE;EACzC,CAAC;CAEF,MAAM,UAAU,uBAAuB;EACrC;EACA;EACD,CAAC;CAEF,MAAMA,QAAqBC,IAAsB,EAAE,SA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AAM,IAAI,MACR,wFACD;GAGH,MAAM,UAAU,YAAY;GAC5B,IAAI,iBACF,OAAO;GAGT,MAAM,cAAc,QAAQ;GAC5B,OAAO;;EAET,UAAU;GACR,OAAO,YAAY;;EAErB,QAKE,aACA,UAC+D;GAC/D,OAAO,YAAY,CAAC,QAAoB,cAAc,WAAW,SAASF,OAAK,OAAO,CAAC;;EAE1F"}
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["sql","sqlBuilder","ormBuilder"],"sources":["../src/runtime/binding.ts","../src/runtime/sqlite.ts"],"sourcesContent":["import type { SqliteBinding } from '@prisma-next/driver-sqlite/runtime';\n\nexport type SqliteBindingInput = { readonly path: string };\n\nexport function resolveSqliteBinding(input: SqliteBindingInput): SqliteBinding {\n return { kind: 'path', path: input.path };\n}\n\nexport function resolveOptionalSqliteBinding(options: {\n readonly path?: string;\n}): SqliteBinding | undefined {\n if (options.path === undefined) {\n return undefined;\n }\n return { kind: 'path', path: options.path };\n}\n","import sqliteAdapter from '@prisma-next/adapter-sqlite/runtime';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { SqliteBinding } from '@prisma-next/driver-sqlite/runtime';\nimport sqliteDriver from '@prisma-next/driver-sqlite/runtime';\nimport { SqlContractSerializer } from '@prisma-next/family-sql/ir';\nimport { instantiateExecutionStack } from '@prisma-next/framework-components/execution';\nimport { sql as sqlBuilder } from '@prisma-next/sql-builder/runtime';\nimport type { Db } from '@prisma-next/sql-builder/types';\nimport type { ExtractCodecTypes, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { orm as ormBuilder } from '@prisma-next/sql-orm-client';\nimport type { CodecTypesBase } from '@prisma-next/sql-relational-core/expression';\nimport type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';\nimport type {\n BindSiteParams,\n Declaration,\n ExecutionContext,\n ParamsFromDeclaration,\n PreparedStatement,\n Runtime,\n RuntimeVerifyOptions,\n SqlExecutionStackWithDriver,\n SqlMiddleware,\n SqlRuntimeExtensionDescriptor,\n} from '@prisma-next/sql-runtime';\nimport {\n createExecutionContext,\n createRuntime,\n createSqlExecutionStack,\n} from '@prisma-next/sql-runtime';\nimport sqliteTarget from '@prisma-next/target-sqlite/runtime';\nimport { resolveOptionalSqliteBinding, resolveSqliteBinding } from './binding';\n\nexport type SqliteTargetId = 'sqlite';\ntype OrmClient<TContract extends Contract<SqlStorage>> = ReturnType<typeof ormBuilder<TContract>>;\n\nexport interface SqliteClient<TContract extends Contract<SqlStorage>> {\n readonly sql: Db<TContract>;\n readonly orm: OrmClient<TContract>;\n readonly context: ExecutionContext<TContract>;\n readonly stack: SqlExecutionStackWithDriver<SqliteTargetId>;\n connect(bindingInput?: { readonly path: string }): Promise<Runtime>;\n runtime(): Runtime;\n prepare<\n D extends Declaration<CT>,\n Row,\n CT extends CodecTypesBase = ExtractCodecTypes<TContract> & CodecTypesBase,\n >(\n declaration: D,\n callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>,\n ): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>>;\n close(): Promise<void>;\n [Symbol.asyncDispose](): Promise<void>;\n}\n\nexport interface SqliteOptionsBase {\n readonly extensions?: readonly SqlRuntimeExtensionDescriptor<SqliteTargetId>[];\n readonly middleware?: readonly SqlMiddleware[];\n readonly verify?: RuntimeVerifyOptions;\n}\n\nexport type SqliteOptionsWithContract<TContract extends Contract<SqlStorage>> = {\n readonly path?: string;\n} & SqliteOptionsBase & {\n readonly contract: TContract;\n readonly contractJson?: never;\n };\n\nexport type SqliteOptionsWithContractJson<TContract extends Contract<SqlStorage>> = {\n readonly path?: string;\n readonly _contract?: TContract;\n} & SqliteOptionsBase & {\n readonly contractJson: unknown;\n readonly contract?: never;\n };\n\nexport type SqliteOptions<TContract extends Contract<SqlStorage>> =\n | SqliteOptionsWithContract<TContract>\n | SqliteOptionsWithContractJson<TContract>;\n\nfunction resolveContract<TContract extends Contract<SqlStorage>>(\n options: SqliteOptions<TContract>,\n): TContract {\n const contractInput =\n 'contractJson' in options && options.contractJson !== undefined\n ? options.contractJson\n : (options as SqliteOptionsWithContract<TContract>).contract;\n return new SqlContractSerializer().deserializeContract(contractInput) as TContract;\n}\n\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptionsWithContract<TContract>,\n): SqliteClient<TContract>;\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptionsWithContractJson<TContract>,\n): SqliteClient<TContract>;\nexport default function sqlite<TContract extends Contract<SqlStorage>>(\n options: SqliteOptions<TContract>,\n): SqliteClient<TContract> {\n const contract = resolveContract(options);\n let binding = resolveOptionalSqliteBinding(options);\n const stack = createSqlExecutionStack({\n target: sqliteTarget,\n adapter: sqliteAdapter,\n driver: sqliteDriver,\n extensionPacks: options.extensions ?? [],\n });\n\n const context = createExecutionContext({\n contract,\n stack,\n });\n\n const sql: Db<TContract> = sqlBuilder<TContract>({ context });\n let runtimeInstance: Runtime | undefined;\n let runtimeDriver: { connect(binding: unknown): Promise<void> } | undefined;\n let driverConnected = false;\n let connectPromise: Promise<void> | undefined;\n let closePromise: Promise<void> | undefined;\n let backgroundConnectError: unknown;\n let closed = false;\n let ownedDispose: (() => Promise<void>) | undefined;\n\n const connectDriver = async (resolvedBinding: SqliteBinding): Promise<void> => {\n if (driverConnected) return;\n if (!runtimeDriver) throw new Error('SQLite runtime driver missing');\n if (connectPromise) return connectPromise;\n connectPromise = runtimeDriver\n .connect(resolvedBinding)\n .then(() => {\n driverConnected = true;\n })\n .catch((err) => {\n backgroundConnectError = err;\n connectPromise = undefined;\n throw err;\n });\n return connectPromise;\n };\n\n const getRuntime = (): Runtime => {\n if (closed) {\n throw new Error('SQLite client is closed');\n }\n\n if (backgroundConnectError !== undefined) {\n throw backgroundConnectError;\n }\n\n if (runtimeInstance) {\n return runtimeInstance;\n }\n\n const stackInstance = instantiateExecutionStack(stack);\n const driverDescriptor = stack.driver;\n if (!driverDescriptor) {\n throw new Error('Driver descriptor missing from execution stack');\n }\n\n const driver = driverDescriptor.create();\n ownedDispose = () => driver.close();\n runtimeDriver = driver;\n if (binding !== undefined) {\n void connectDriver(binding).catch(() => undefined);\n }\n\n runtimeInstance = createRuntime({\n stackInstance,\n context,\n driver,\n verify: options.verify ?? { mode: 'onFirstUse', requireMarker: false },\n ...(options.middleware ? { middleware: options.middleware } : {}),\n });\n\n return runtimeInstance;\n };\n\n const orm: OrmClient<TContract> = ormBuilder({\n context,\n runtime: {\n execute(plan) {\n return getRuntime().execute(plan);\n },\n connection() {\n return getRuntime().connection();\n },\n },\n });\n\n return {\n sql,\n orm,\n context,\n stack,\n async connect(bindingInput) {\n if (closed) {\n throw new Error('SQLite client is closed');\n }\n\n if (driverConnected || connectPromise) {\n throw new Error('SQLite client already connected');\n }\n\n backgroundConnectError = undefined;\n\n if (bindingInput !== undefined) {\n binding = resolveSqliteBinding(bindingInput);\n }\n\n if (binding === undefined) {\n throw new Error(\n 'SQLite binding not configured. Pass path to sqlite(...) or call db.connect({ path }).',\n );\n }\n\n const runtime = getRuntime();\n if (driverConnected) {\n return runtime;\n }\n\n await connectDriver(binding);\n return runtime;\n },\n runtime() {\n return getRuntime();\n },\n prepare<\n D extends Declaration<CT>,\n Row,\n CT extends CodecTypesBase = ExtractCodecTypes<TContract> & CodecTypesBase,\n >(\n declaration: D,\n callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>,\n ): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>> {\n return getRuntime().prepare<D, Row, CT>(declaration, (params) => callback(sql, params));\n },\n\n close(): Promise<void> {\n if (closePromise) return closePromise;\n closed = true;\n closePromise = (async () => {\n await connectPromise?.catch(() => undefined);\n await ownedDispose?.();\n })();\n return closePromise;\n },\n\n [Symbol.asyncDispose](): Promise<void> {\n return this.close();\n },\n };\n}\n"],"mappings":";;;;;;;;;AAIA,SAAgB,qBAAqB,OAA0C;CAC7E,OAAO;EAAE,MAAM;EAAQ,MAAM,MAAM;EAAM;;AAG3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isma-next/sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "One-liner lazy SQLite client composition for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/adapter-sqlite": "0.
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/sql
|
|
15
|
-
"@prisma-next/
|
|
16
|
-
"@prisma-next/sql-
|
|
17
|
-
"@prisma-next/sql-
|
|
18
|
-
"@prisma-next/sql-
|
|
19
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/adapter-sqlite": "0.11.0",
|
|
10
|
+
"@prisma-next/cli": "0.11.0",
|
|
11
|
+
"@prisma-next/config": "0.11.0",
|
|
12
|
+
"@prisma-next/contract": "0.11.0",
|
|
13
|
+
"@prisma-next/driver-sqlite": "0.11.0",
|
|
14
|
+
"@prisma-next/family-sql": "0.11.0",
|
|
15
|
+
"@prisma-next/framework-components": "0.11.0",
|
|
16
|
+
"@prisma-next/sql-builder": "0.11.0",
|
|
17
|
+
"@prisma-next/sql-contract": "0.11.0",
|
|
18
|
+
"@prisma-next/sql-contract-psl": "0.11.0",
|
|
19
|
+
"@prisma-next/sql-contract-ts": "0.11.0",
|
|
20
|
+
"@prisma-next/sql-orm-client": "0.11.0",
|
|
21
|
+
"@prisma-next/sql-relational-core": "0.11.0",
|
|
22
|
+
"@prisma-next/sql-runtime": "0.11.0",
|
|
23
|
+
"@prisma-next/target-sqlite": "0.11.0",
|
|
24
|
+
"@prisma-next/utils": "0.11.0",
|
|
25
|
+
"pathe": "^2.0.3"
|
|
20
26
|
},
|
|
21
27
|
"devDependencies": {
|
|
22
|
-
"@prisma-next/test-utils": "0.
|
|
23
|
-
"@prisma-next/tsconfig": "0.
|
|
24
|
-
"@prisma-next/tsdown": "0.
|
|
28
|
+
"@prisma-next/test-utils": "0.11.0",
|
|
29
|
+
"@prisma-next/tsconfig": "0.11.0",
|
|
30
|
+
"@prisma-next/tsdown": "0.11.0",
|
|
25
31
|
"tsdown": "0.22.0",
|
|
26
32
|
"typescript": "5.9.3",
|
|
27
33
|
"vitest": "4.1.6"
|
|
@@ -36,6 +42,10 @@
|
|
|
36
42
|
"directory": "packages/3-extensions/sqlite"
|
|
37
43
|
},
|
|
38
44
|
"exports": {
|
|
45
|
+
"./config": "./dist/config.mjs",
|
|
46
|
+
"./contract-builder": "./dist/contract-builder.mjs",
|
|
47
|
+
"./control": "./dist/control.mjs",
|
|
48
|
+
"./migration": "./dist/migration.mjs",
|
|
39
49
|
"./runtime": "./dist/runtime.mjs",
|
|
40
50
|
"./package.json": "./package.json"
|
|
41
51
|
},
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import sqliteAdapter from '@prisma-next/adapter-sqlite/control';
|
|
2
|
+
import type { PrismaNextConfig } from '@prisma-next/config/config-types';
|
|
3
|
+
import { defineConfig as coreDefineConfig } from '@prisma-next/config/config-types';
|
|
4
|
+
import sqliteDriver from '@prisma-next/driver-sqlite/control';
|
|
5
|
+
import sql from '@prisma-next/family-sql/control';
|
|
6
|
+
import type { ControlExtensionDescriptor } from '@prisma-next/framework-components/control';
|
|
7
|
+
import { prismaContract } from '@prisma-next/sql-contract-psl/provider';
|
|
8
|
+
import { typescriptContractFromPath } from '@prisma-next/sql-contract-ts/config-types';
|
|
9
|
+
import sqlite from '@prisma-next/target-sqlite/control';
|
|
10
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
11
|
+
import { extname } from 'pathe';
|
|
12
|
+
|
|
13
|
+
export interface SqliteConfigOptions {
|
|
14
|
+
readonly contract: string;
|
|
15
|
+
readonly db?: {
|
|
16
|
+
readonly connection?: string;
|
|
17
|
+
};
|
|
18
|
+
readonly extensions?: readonly ControlExtensionDescriptor<'sql', 'sqlite'>[];
|
|
19
|
+
readonly migrations?: {
|
|
20
|
+
readonly dir?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function deriveOutputPath(contractPath: string): string {
|
|
25
|
+
const ext = extname(contractPath);
|
|
26
|
+
if (ext.length === 0) {
|
|
27
|
+
return `${contractPath}.json`;
|
|
28
|
+
}
|
|
29
|
+
return `${contractPath.slice(0, -ext.length)}.json`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function defineConfig(options: SqliteConfigOptions): PrismaNextConfig<'sql', 'sqlite'> {
|
|
33
|
+
const extensions = options.extensions ?? [];
|
|
34
|
+
const output = deriveOutputPath(options.contract);
|
|
35
|
+
const ext = extname(options.contract);
|
|
36
|
+
|
|
37
|
+
const contractConfig =
|
|
38
|
+
ext === '.ts'
|
|
39
|
+
? typescriptContractFromPath(options.contract, output)
|
|
40
|
+
: prismaContract(options.contract, {
|
|
41
|
+
output,
|
|
42
|
+
target: sqlite,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return coreDefineConfig({
|
|
46
|
+
family: sql,
|
|
47
|
+
target: sqlite,
|
|
48
|
+
adapter: sqliteAdapter,
|
|
49
|
+
driver: sqliteDriver,
|
|
50
|
+
extensionPacks: extensions,
|
|
51
|
+
contract: contractConfig,
|
|
52
|
+
...ifDefined('db', options.db),
|
|
53
|
+
...ifDefined('migrations', options.migrations),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import sqlFamilyPack from '@prisma-next/family-sql/pack';
|
|
2
|
+
import type { ExtensionPackRef } from '@prisma-next/framework-components/components';
|
|
3
|
+
import type { StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import type {
|
|
5
|
+
ComposedAuthoringHelpers,
|
|
6
|
+
ContractInput,
|
|
7
|
+
ModelLike,
|
|
8
|
+
} from '@prisma-next/sql-contract-ts/contract-builder';
|
|
9
|
+
import { defineContract as baseDefineContract } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
10
|
+
import sqlitePack from '@prisma-next/target-sqlite/pack';
|
|
11
|
+
|
|
12
|
+
type SqlFamily = typeof sqlFamilyPack;
|
|
13
|
+
type SqlitePack = typeof sqlitePack;
|
|
14
|
+
|
|
15
|
+
type TypesConstraint = Record<string, StorageTypeInstance>;
|
|
16
|
+
type ModelsConstraint = Record<string, ModelLike>;
|
|
17
|
+
|
|
18
|
+
// Return type threaded with all inferred type params.
|
|
19
|
+
// We override target/targetFamily via intersection to preserve the literal values
|
|
20
|
+
// ('sqlite', 'sql') even when TypeScript defers conditional-type evaluation on
|
|
21
|
+
// unresolved generic params.
|
|
22
|
+
type SqliteResult<
|
|
23
|
+
Types extends TypesConstraint,
|
|
24
|
+
Models extends ModelsConstraint,
|
|
25
|
+
ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,
|
|
26
|
+
Capabilities extends Record<string, Record<string, boolean>> | undefined,
|
|
27
|
+
> = Omit<
|
|
28
|
+
ReturnType<
|
|
29
|
+
typeof baseDefineContract<SqlFamily, SqlitePack, Types, Models, ExtensionPacks, Capabilities>
|
|
30
|
+
>,
|
|
31
|
+
'target' | 'targetFamily'
|
|
32
|
+
> & {
|
|
33
|
+
readonly target: SqlitePack['targetId'];
|
|
34
|
+
readonly targetFamily: SqlFamily['familyId'];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Scaffold that carries all ContractInput fields EXCEPT family, target, types, models.
|
|
38
|
+
// Built from ContractInput with concrete Record<never, never> defaults to avoid
|
|
39
|
+
// the ContractInput Models constraint (which requires ContractModelBuilder, not ModelLike).
|
|
40
|
+
type SqliteBaseScaffold<
|
|
41
|
+
ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,
|
|
42
|
+
Capabilities extends Record<string, Record<string, boolean>> | undefined,
|
|
43
|
+
> = Omit<
|
|
44
|
+
ContractInput<
|
|
45
|
+
SqlFamily,
|
|
46
|
+
SqlitePack,
|
|
47
|
+
Record<never, never>,
|
|
48
|
+
Record<never, never>,
|
|
49
|
+
ExtensionPacks,
|
|
50
|
+
Capabilities
|
|
51
|
+
>,
|
|
52
|
+
'family' | 'target' | 'types' | 'models'
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
// Definition form: inline types + models (uses ModelLike for models, not ContractModelBuilder)
|
|
56
|
+
type SqliteDefinition<
|
|
57
|
+
Types extends TypesConstraint,
|
|
58
|
+
Models extends ModelsConstraint,
|
|
59
|
+
ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,
|
|
60
|
+
Capabilities extends Record<string, Record<string, boolean>> | undefined,
|
|
61
|
+
> = SqliteBaseScaffold<ExtensionPacks, Capabilities> & {
|
|
62
|
+
readonly types?: Types;
|
|
63
|
+
readonly models?: Models;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Factory form: scaffold without types/models (factory provides them)
|
|
67
|
+
type SqliteScaffold<
|
|
68
|
+
ExtensionPacks extends Record<string, ExtensionPackRef<'sql', string>> | undefined,
|
|
69
|
+
Capabilities extends Record<string, Record<string, boolean>> | undefined,
|
|
70
|
+
> = SqliteBaseScaffold<ExtensionPacks, Capabilities>;
|
|
71
|
+
|
|
72
|
+
// Overload 1: definition form (models/types inline in scaffold)
|
|
73
|
+
export function defineContract<
|
|
74
|
+
const Types extends TypesConstraint = Record<never, never>,
|
|
75
|
+
const Models extends ModelsConstraint = Record<never, never>,
|
|
76
|
+
const ExtensionPacks extends
|
|
77
|
+
| Record<string, ExtensionPackRef<'sql', string>>
|
|
78
|
+
| undefined = undefined,
|
|
79
|
+
const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
80
|
+
>(
|
|
81
|
+
definition: SqliteDefinition<Types, Models, ExtensionPacks, Capabilities>,
|
|
82
|
+
): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;
|
|
83
|
+
|
|
84
|
+
// Overload 2: factory form (scaffold without models/types; factory provides them)
|
|
85
|
+
export function defineContract<
|
|
86
|
+
const Types extends TypesConstraint = Record<never, never>,
|
|
87
|
+
const Models extends ModelsConstraint = Record<never, never>,
|
|
88
|
+
const ExtensionPacks extends
|
|
89
|
+
| Record<string, ExtensionPackRef<'sql', string>>
|
|
90
|
+
| undefined = undefined,
|
|
91
|
+
const Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
92
|
+
>(
|
|
93
|
+
scaffold: SqliteScaffold<ExtensionPacks, Capabilities>,
|
|
94
|
+
factory: (helpers: ComposedAuthoringHelpers<SqlFamily, SqlitePack, ExtensionPacks>) => {
|
|
95
|
+
readonly types?: Types;
|
|
96
|
+
readonly models?: Models;
|
|
97
|
+
},
|
|
98
|
+
): SqliteResult<Types, Models, ExtensionPacks, Capabilities>;
|
|
99
|
+
|
|
100
|
+
// Implementation — the runtime type is richer than the wide impl signature;
|
|
101
|
+
// as unknown is safe because every declared overload produces a SqliteResult.
|
|
102
|
+
export function defineContract(
|
|
103
|
+
scaffold: Omit<ContractInput, 'family' | 'target'>,
|
|
104
|
+
factory?: (helpers: ComposedAuthoringHelpers<SqlFamily, SqlitePack, undefined>) => {
|
|
105
|
+
readonly types?: TypesConstraint;
|
|
106
|
+
readonly models?: ModelsConstraint;
|
|
107
|
+
},
|
|
108
|
+
): SqliteResult<TypesConstraint, ModelsConstraint, undefined, undefined> {
|
|
109
|
+
const full = {
|
|
110
|
+
...scaffold,
|
|
111
|
+
family: sqlFamilyPack,
|
|
112
|
+
target: sqlitePack,
|
|
113
|
+
} as ContractInput;
|
|
114
|
+
if (factory !== undefined) {
|
|
115
|
+
return baseDefineContract(
|
|
116
|
+
full,
|
|
117
|
+
factory as Parameters<typeof baseDefineContract>[1],
|
|
118
|
+
) as unknown as SqliteResult<TypesConstraint, ModelsConstraint, undefined, undefined>;
|
|
119
|
+
}
|
|
120
|
+
return baseDefineContract(full) as unknown as SqliteResult<
|
|
121
|
+
TypesConstraint,
|
|
122
|
+
ModelsConstraint,
|
|
123
|
+
undefined,
|
|
124
|
+
undefined
|
|
125
|
+
>;
|
|
126
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ComposedAuthoringHelpers,
|
|
3
|
+
ContractDefinition,
|
|
4
|
+
ContractInput,
|
|
5
|
+
ContractModelBuilder,
|
|
6
|
+
FieldNode,
|
|
7
|
+
ForeignKeyNode,
|
|
8
|
+
IndexNode,
|
|
9
|
+
ModelLike,
|
|
10
|
+
ModelNode,
|
|
11
|
+
PrimaryKeyNode,
|
|
12
|
+
RelationNode,
|
|
13
|
+
ScalarFieldBuilder,
|
|
14
|
+
UniqueConstraintNode,
|
|
15
|
+
} from '@prisma-next/sql-contract-ts/contract-builder';
|
|
16
|
+
export { field, model, rel } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
17
|
+
export { defineContract } from '../contract/define-contract';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import sqliteAdapter from '@prisma-next/adapter-sqlite/control';
|
|
2
|
+
import {
|
|
3
|
+
type ControlClient,
|
|
4
|
+
type ControlClientOptions,
|
|
5
|
+
createControlClient,
|
|
6
|
+
} from '@prisma-next/cli/control-api';
|
|
7
|
+
import sqliteDriver from '@prisma-next/driver-sqlite/control';
|
|
8
|
+
import sql from '@prisma-next/family-sql/control';
|
|
9
|
+
import sqlite from '@prisma-next/target-sqlite/control';
|
|
10
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
11
|
+
|
|
12
|
+
export interface SqliteControlClientOptions {
|
|
13
|
+
readonly connection?: string;
|
|
14
|
+
readonly extensionPacks?: ControlClientOptions['extensionPacks'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createSqliteControlClient(options: SqliteControlClientOptions = {}): ControlClient {
|
|
18
|
+
const clientOptions: ControlClientOptions = {
|
|
19
|
+
family: sql,
|
|
20
|
+
target: sqlite,
|
|
21
|
+
adapter: sqliteAdapter,
|
|
22
|
+
driver: sqliteDriver,
|
|
23
|
+
...ifDefined('connection', options.connection),
|
|
24
|
+
...ifDefined('extensionPacks', options.extensionPacks),
|
|
25
|
+
};
|
|
26
|
+
return createControlClient(clientOptions);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type { ControlClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@prisma-next/target-sqlite/migration';
|
package/src/runtime/sqlite.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface SqliteClient<TContract extends Contract<SqlStorage>> {
|
|
|
48
48
|
declaration: D,
|
|
49
49
|
callback: (sql: Db<TContract>, params: BindSiteParams<D>) => SqlQueryPlan<Row>,
|
|
50
50
|
): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export interface SqliteOptionsBase {
|
|
@@ -113,7 +115,10 @@ export default function sqlite<TContract extends Contract<SqlStorage>>(
|
|
|
113
115
|
let runtimeDriver: { connect(binding: unknown): Promise<void> } | undefined;
|
|
114
116
|
let driverConnected = false;
|
|
115
117
|
let connectPromise: Promise<void> | undefined;
|
|
118
|
+
let closePromise: Promise<void> | undefined;
|
|
116
119
|
let backgroundConnectError: unknown;
|
|
120
|
+
let closed = false;
|
|
121
|
+
let ownedDispose: (() => Promise<void>) | undefined;
|
|
117
122
|
|
|
118
123
|
const connectDriver = async (resolvedBinding: SqliteBinding): Promise<void> => {
|
|
119
124
|
if (driverConnected) return;
|
|
@@ -133,6 +138,10 @@ export default function sqlite<TContract extends Contract<SqlStorage>>(
|
|
|
133
138
|
};
|
|
134
139
|
|
|
135
140
|
const getRuntime = (): Runtime => {
|
|
141
|
+
if (closed) {
|
|
142
|
+
throw new Error('SQLite client is closed');
|
|
143
|
+
}
|
|
144
|
+
|
|
136
145
|
if (backgroundConnectError !== undefined) {
|
|
137
146
|
throw backgroundConnectError;
|
|
138
147
|
}
|
|
@@ -148,6 +157,7 @@ export default function sqlite<TContract extends Contract<SqlStorage>>(
|
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
const driver = driverDescriptor.create();
|
|
160
|
+
ownedDispose = () => driver.close();
|
|
151
161
|
runtimeDriver = driver;
|
|
152
162
|
if (binding !== undefined) {
|
|
153
163
|
void connectDriver(binding).catch(() => undefined);
|
|
@@ -182,6 +192,10 @@ export default function sqlite<TContract extends Contract<SqlStorage>>(
|
|
|
182
192
|
context,
|
|
183
193
|
stack,
|
|
184
194
|
async connect(bindingInput) {
|
|
195
|
+
if (closed) {
|
|
196
|
+
throw new Error('SQLite client is closed');
|
|
197
|
+
}
|
|
198
|
+
|
|
185
199
|
if (driverConnected || connectPromise) {
|
|
186
200
|
throw new Error('SQLite client already connected');
|
|
187
201
|
}
|
|
@@ -219,5 +233,19 @@ export default function sqlite<TContract extends Contract<SqlStorage>>(
|
|
|
219
233
|
): Promise<PreparedStatement<ParamsFromDeclaration<D, CT>, Row>> {
|
|
220
234
|
return getRuntime().prepare<D, Row, CT>(declaration, (params) => callback(sql, params));
|
|
221
235
|
},
|
|
236
|
+
|
|
237
|
+
close(): Promise<void> {
|
|
238
|
+
if (closePromise) return closePromise;
|
|
239
|
+
closed = true;
|
|
240
|
+
closePromise = (async () => {
|
|
241
|
+
await connectPromise?.catch(() => undefined);
|
|
242
|
+
await ownedDispose?.();
|
|
243
|
+
})();
|
|
244
|
+
return closePromise;
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
[Symbol.asyncDispose](): Promise<void> {
|
|
248
|
+
return this.close();
|
|
249
|
+
},
|
|
222
250
|
};
|
|
223
251
|
}
|