Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f2fa687
refactor: move schema-gen tests to its own package
WhyAsh5114 Mar 22, 2026
a11afef
refactor: update function signatures to use options object for better…
WhyAsh5114 Mar 22, 2026
831ad68
feat: add dropDbOnSchemaVersionMismatch option to generator config
WhyAsh5114 Mar 22, 2026
a57242a
feat: implement migration helper functions and snapshot types
WhyAsh5114 Mar 22, 2026
055575e
feat: add migration file generation and snapshot handling
WhyAsh5114 Mar 22, 2026
786e799
refactor: update createScopedSchemaFile to accept options object for …
WhyAsh5114 Mar 22, 2026
f44586c
feat: enhance migration handling by integrating MigrationInfo and upd…
WhyAsh5114 Mar 22, 2026
e3c6596
chore: output change for hash based drift detection
WhyAsh5114 Mar 22, 2026
d64df5f
refactor: simplify snapshot export by removing type definition and re…
WhyAsh5114 Mar 22, 2026
34aaf2b
refactor: change tests package structure
WhyAsh5114 Mar 22, 2026
0b4000f
fix: correct syntax for snapshot export in createDmmfSnapshotFile
WhyAsh5114 Mar 22, 2026
8a3126a
feat: add migration schemas and update .gitignore for generated files
WhyAsh5114 Mar 22, 2026
99b59fb
fix: add handling for prisma schema folders
WhyAsh5114 Mar 22, 2026
1b010a0
feat: enhance migration generation with version-aware schema and type…
WhyAsh5114 Mar 22, 2026
35c768b
refactor: remove unused prismaToTsTypeMap and consolidate type mappin…
WhyAsh5114 Mar 22, 2026
a74c21e
refactor: simplify createDmmfSnapshotFile by removing snapshot export…
WhyAsh5114 Mar 22, 2026
4f57710
test: update migration generation tests to check for MigrationSchema …
WhyAsh5114 Mar 22, 2026
277236a
lint: prettier and eslint
WhyAsh5114 Mar 22, 2026
900fe5d
fix: update IDB_SCHEMA_HASH values in auto-generated files
WhyAsh5114 Mar 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export interface PrismaIDBSchema extends DBSchema {
key: [model: string, key: IDBValidKey];
value: ChangeMetaRecord;
};
_idb_meta: {
key: string;
value: string;
};
}
export interface OutboxEventRecord {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Auto-generated by idb-client-generator — always regenerated
export const IDB_SCHEMA_HASH = "56b52d79";
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./prisma-idb-client";
export * from "./idb-interface";
export * from "./idb-utils";
export * from "./apply-pull";
export * from "./idb-schema-hash";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { openDB } from "idb";
import { openDB, deleteDB } from "idb";
import type { IDBPDatabase, StoreNames, IDBPTransaction } from "idb";
import type { Prisma } from "./generated/client";
import * as IDBUtils from "./idb-utils";
Expand All @@ -14,8 +14,10 @@ import type { PushResult } from "../server/batch-processor";
import { validators, keyPathValidators, modelRecordToKeyPath } from "../validators";
import type { LogWithStringifiedRecord } from "../server/batch-processor";
import { applyPull, type ApplyPullResult } from "./apply-pull";
import { IDB_SCHEMA_HASH } from "./idb-schema-hash";
import { v4 as uuidv4 } from "uuid";
const IDB_VERSION = 1;
const DROP_DB_ON_SCHEMA_VERSION_MISMATCH = false;
type CreateSyncWorkerOptions = {
push: {
handler: (events: OutboxEventRecord[]) => Promise<PushResult[]>;
Expand Down Expand Up @@ -52,6 +54,18 @@ export class PrismaIDBClient {
if (!PrismaIDBClient.instance) {
const client = new PrismaIDBClient();
await client.initialize();
const storedHash = await client._db.get("_idb_meta", "schemaHash");
if (storedHash !== undefined && storedHash !== IDB_SCHEMA_HASH) {
client._db.close();
if (!DROP_DB_ON_SCHEMA_VERSION_MISMATCH) {
throw new Error(
`IDB schema mismatch: stored hash "${storedHash}" does not match expected "${IDB_SCHEMA_HASH}". Set dropDbOnSchemaVersionMismatch = true in your generator config to automatically reset the database.`
);
}
await deleteDB("prisma-idb");
return PrismaIDBClient.createClient();
}
await client._db.put("_idb_meta", IDB_SCHEMA_HASH, "schemaHash");
PrismaIDBClient.instance = client;
}
return PrismaIDBClient.instance;
Expand Down Expand Up @@ -439,16 +453,21 @@ export class PrismaIDBClient {
};
}
private async initialize() {
this._db = await openDB<PrismaIDBSchema>("prisma-idb", IDB_VERSION, {
const db = await openDB<PrismaIDBSchema>("prisma-idb", IDB_VERSION, {
upgrade(db) {
db.createObjectStore("Board", { keyPath: ["id"] });
db.createObjectStore("Todo", { keyPath: ["id"] });
const UserStore = db.createObjectStore("User", { keyPath: ["id"] });
UserStore.createIndex("emailIndex", ["email"], { unique: true });
db.createObjectStore("OutboxEvent", { keyPath: ["id"] });
db.createObjectStore("VersionMeta", { keyPath: ["model", "key"] });
db.createObjectStore("_idb_meta");
},
blocking() {
db.close();
},
Comment on lines +456 to 468
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

files=(
  apps/pidb-kanban-example/src/lib/prisma-idb/client/prisma-idb-client.ts
)

if [ -f packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts ]; then
  files+=(packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts)
fi

rg -n -C2 'const IDB_VERSION =|CURRENT_VERSION|get\("_idb_meta"|put\("_idb_meta"|createObjectStore\("_idb_meta"' "${files[@]}"

Repository: prisma-idb/idb-client-generator

Length of output: 5112


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for version-related constants and logic in the generator
rg -n 'IDB_VERSION|CURRENT_VERSION|version.*=|increment.*version' \
  packages/generator/src/fileCreators/prisma-idb-client/ -A 2 -B 2 | head -100

Repository: prisma-idb/idb-client-generator

Length of output: 3503


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check the full PrismaIDBClient.ts generator to understand version handling
wc -l packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts

Repository: prisma-idb/idb-client-generator

Length of output: 159


🏁 Script executed:

#!/bin/bash
set -eulo pipefail

# Search for where IDB_VERSION or version constants are written in the generator
rg -n 'writeLine.*VERSION|IDB_VERSION|const.*VERSION' \
  packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts

Repository: prisma-idb/idb-client-generator

Length of output: 403


Fix IndexedDB schema upgrade path: bump version when introducing _idb_meta store.

The generated code adds _idb_meta store in the upgrade() callback (line 464) but uses the legacy path with hardcoded IDB_VERSION = 1 (line 19). Existing users with a v1 database will not trigger the upgrade callback, so _idb_meta is never created. The subsequent schema-drift check at line 57 (await client._db.get("_idb_meta", "schemaHash")) fails instead of detecting drift.

The generator has two code paths: a migration-based path using CURRENT_VERSION (when migration info is available) and a legacy path using hardcoded IDB_VERSION = 1. The generated example uses the legacy path. When adding new object stores, ensure the version is incremented in the generator's version declaration logic, or migrate to the migration-based upgrade callback in packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/pidb-kanban-example/src/lib/prisma-idb/client/prisma-idb-client.ts`
around lines 456 - 468, The IndexedDB upgrade callback adds the "_idb_meta"
store but the file still uses the legacy hardcoded IDB_VERSION (IDB_VERSION =
1), so existing DBs won't trigger upgrade; fix by bumping the IDB version
constant (IDB_VERSION) to a higher integer or switch the generated client to use
the migration-based CURRENT_VERSION path used by the generator, ensuring the
openDB(...) call's upgrade() runs and creates "_idb_meta" (referencing openDB,
upgrade, IDB_VERSION and the "_idb_meta" store) and update any schema-drift
check that reads client._db.get("_idb_meta", "schemaHash") to match the new
versioning approach.

});
this._db = db;
this.board = new BoardIDBClass(this, ["id"]);
this.todo = new TodoIDBClass(this, ["id"]);
this.user = new UserIDBClass(this, ["id"]);
Expand Down
4 changes: 4 additions & 0 deletions apps/usage/src/lib/prisma-idb/client/idb-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ export interface PrismaIDBSchema extends DBSchema {
key: [id: Prisma.Todo["id"]];
value: Prisma.Todo;
};
_idb_meta: {
key: string;
value: string;
};
}
2 changes: 2 additions & 0 deletions apps/usage/src/lib/prisma-idb/client/idb-schema-hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Auto-generated by idb-client-generator — always regenerated
export const IDB_SCHEMA_HASH = "d1c83f66";
1 change: 1 addition & 0 deletions apps/usage/src/lib/prisma-idb/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./prisma-idb-client";
export * from "./idb-interface";
export * from "./idb-utils";
export * from "./idb-schema-hash";
23 changes: 21 additions & 2 deletions apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { openDB } from "idb";
import { openDB, deleteDB } from "idb";
import type { IDBPDatabase, StoreNames, IDBPTransaction } from "idb";
import type { Prisma } from "../../generated/prisma/client";
import * as IDBUtils from "./idb-utils";
import type { PrismaIDBSchema } from "./idb-interface";
import { IDB_SCHEMA_HASH } from "./idb-schema-hash";
import { createId } from "@paralleldrive/cuid2";
import { v4 as uuidv4 } from "uuid";
const IDB_VERSION = 1;
const DROP_DB_ON_SCHEMA_VERSION_MISMATCH = false;
export class PrismaIDBClient {
private static instance: PrismaIDBClient;
_db!: IDBPDatabase<PrismaIDBSchema>;
Expand Down Expand Up @@ -51,6 +53,18 @@ export class PrismaIDBClient {
if (!PrismaIDBClient.instance) {
const client = new PrismaIDBClient();
await client.initialize();
const storedHash = await client._db.get("_idb_meta", "schemaHash");
if (storedHash !== undefined && storedHash !== IDB_SCHEMA_HASH) {
client._db.close();
if (!DROP_DB_ON_SCHEMA_VERSION_MISMATCH) {
throw new Error(
`IDB schema mismatch: stored hash "${storedHash}" does not match expected "${IDB_SCHEMA_HASH}". Set dropDbOnSchemaVersionMismatch = true in your generator config to automatically reset the database.`
);
}
await deleteDB("prisma-idb");
return PrismaIDBClient.createClient();
}
await client._db.put("_idb_meta", IDB_SCHEMA_HASH, "schemaHash");
Comment on lines +56 to +67
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect generated clients/templates for DB versioning and meta-store upgrade handling.
fd 'prisma-idb-client\.ts$' . -t f | while read -r file; do
  echo "=== $file ==="
  rg -n -C2 'const IDB_VERSION|openDB<|upgrade\(|oldVersion|_idb_meta|schemaHash' "$file"
done

Repository: prisma-idb/idb-client-generator

Length of output: 2586


🏁 Script executed:

# Get the full blocking() callback implementation and singleton handling
sed -n '105,120p' apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts

Repository: prisma-idb/idb-client-generator

Length of output: 841


🏁 Script executed:

# Check for generator templates that produce this file
fd -t f 'prisma-idb-client' packages/generator/src --type f

Repository: prisma-idb/idb-client-generator

Length of output: 57


🏁 Script executed:

# Verify if this is indeed a generated file by checking for generation markers
head -20 apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts

Repository: prisma-idb/idb-client-generator

Length of output: 881


🏁 Script executed:

# Search for the generator template that produces prisma-idb-client.ts
fd -t f 'prisma-idb-client' packages/generator/src

Repository: prisma-idb/idb-client-generator

Length of output: 57


🏁 Script executed:

# Look for the template file by pattern
find packages/generator/src -name '*prisma-idb-client*' -o -name '*client.ts*' | head -20

Repository: prisma-idb/idb-client-generator

Length of output: 128


🏁 Script executed:

# Check the generator directory structure
tree -L 3 packages/generator/src

Repository: prisma-idb/idb-client-generator

Length of output: 1180


🏁 Script executed:

# Inspect the generator template for prisma-idb-client
cat -n packages/generator/src/fileCreators/prisma-idb-client/create.ts | head -150

Repository: prisma-idb/idb-client-generator

Length of output: 5287


🏁 Script executed:

# Search for upgrade and blocking callback in the template
rg -n -A 5 -B 2 'upgrade\(|blocking\(' packages/generator/src/fileCreators/prisma-idb-client/

Repository: prisma-idb/idb-client-generator

Length of output: 4279


🏁 Script executed:

# Check for any version bump logic or migration handling in the generator
rg -n 'IDB_VERSION|oldVersion' packages/generator/src/

Repository: prisma-idb/idb-client-generator

Length of output: 686


🏁 Script executed:

# Check the complete initialization and singleton caching logic
sed -n '40,75p' apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts

Repository: prisma-idb/idb-client-generator

Length of output: 1622


🏁 Script executed:

# Verify the learning about generated code and confirm the fix location
head -5 packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts

Repository: prisma-idb/idb-client-generator

Length of output: 358


Fix _idb_meta store initialization for existing databases and singleton caching after blocking() closes the connection.

Lines 56–67 access _idb_meta immediately after initialize(), but the store is only created in the upgrade() callback. Since IDB_VERSION remains 1, existing user databases won't re-run the upgrade and will lack the _idb_meta store, causing a missing-store error before the drift check executes.

Additionally, the singleton is cached (line 69) before blocking() fires. When another tab requests the database, blocking() closes the connection, leaving the cached instance in a closed state. Subsequent createClient() calls return a closed database.

Both issues originate in the generator template at packages/generator/src/fileCreators/prisma-idb-client/classes/PrismaIDBClient.ts and must be fixed there:

  • Add a version bump and migration to safely create _idb_meta in existing databases.
  • Detect and invalidate the singleton when blocking() closes the database, or defer singleton caching until after the drift check and blocking() setup is complete.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts` around lines 56 -
67, The generated PrismaIDB client currently reads from the "_idb_meta" store
immediately after initialize() and caches the singleton before blocking() can
close the connection, causing missing-store and closed-instance bugs; update the
generator template (PrismaIDBClient.ts) to (1) bump IDB_VERSION and add an
upgrade migration that ensures the "_idb_meta" object store is created on
existing databases so the stored schemaHash lookup succeeds, and (2) move
singleton caching to occur only after the drift check and after setting up
blocking(), or detect when client._db.close() runs inside blocking() and
invalidate the cached singleton (e.g., clear the cached PrismaIDBClient) so
subsequent PrismaIDBClient.createClient() returns a fresh, open connection;
ensure the logic still respects DROP_DB_ON_SCHEMA_VERSION_MISMATCH and the
IDB_SCHEMA_HASH comparison.

PrismaIDBClient.instance = client;
}
return PrismaIDBClient.instance;
Expand All @@ -64,7 +78,7 @@ export class PrismaIDBClient {
return this.outboxEnabled && this.includedModels.has(modelName);
}
private async initialize() {
this._db = await openDB<PrismaIDBSchema>("prisma-idb", IDB_VERSION, {
const db = await openDB<PrismaIDBSchema>("prisma-idb", IDB_VERSION, {
upgrade(db) {
db.createObjectStore("User", { keyPath: ["id"] });
db.createObjectStore("Group", { keyPath: ["id"] });
Expand All @@ -86,8 +100,13 @@ export class PrismaIDBClient {
const ModelWithUniqueAttributesStore = db.createObjectStore("ModelWithUniqueAttributes", { keyPath: ["id"] });
ModelWithUniqueAttributesStore.createIndex("codeIndex", ["code"], { unique: true });
db.createObjectStore("Todo", { keyPath: ["id"] });
db.createObjectStore("_idb_meta");
},
blocking() {
db.close();
},
});
this._db = db;
Comment on lines +105 to +109
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether any close/blocking path clears the cached singleton.
fd 'prisma-idb-client\.ts$' . -t f | while read -r file; do
  echo "=== $file ==="
  rg -n -C3 'private static instance|createClient\(|blocking\(|close\(|instance\s*=' "$file"
done

Repository: prisma-idb/idb-client-generator

Length of output: 3804


Clear the cached singleton instance when blocking() closes the database.

The blocking() callback closes the underlying connection but doesn't clear the static instance variable. The next createClient() call returns the same stale PrismaIDBClient with a closed _db, causing operations to fail.

Suggested fix
-  private static instance: PrismaIDBClient;
+  private static instance: PrismaIDBClient | undefined;
...
       blocking() {
         db.close();
+        if (PrismaIDBClient.instance?._db === db) {
+          PrismaIDBClient.instance = undefined;
+        }
       },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/usage/src/lib/prisma-idb/client/prisma-idb-client.ts` around lines 105 -
109, When the blocking() callback closes the underlying connection it must also
clear the cached singleton so future createClient() calls don't return a stale
PrismaIDBClient with a closed _db; update the blocking() implementation on the
PrismaIDBClient to set the static instance (e.g., PrismaIDBClient.instance or
whatever singleton variable is used) to undefined/null after calling db.close(),
ensuring subsequent createClient() constructs a fresh client with a valid _db.

this.user = new UserIDBClass(this, ["id"]);
this.group = new GroupIDBClass(this, ["id"]);
this.userGroup = new UserGroupIDBClass(this, ["groupId", "userId"]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "turbo run test",
"test:client": "turbo run test --filter=@prisma-idb/usage",
"test:sync": "turbo run test --filter=@prisma-idb/pidb-kanban-example",
"test:schema-gen": "turbo run test --filter=@prisma-idb/tests",
"test:schema-gen": "turbo run test --filter=@prisma-idb/schema-gen-tests",
"test:watch": "turbo run test:watch --no-cache",
"generate": "turbo run generate",
"clean": "turbo clean && rm -rf node_modules",
Expand Down
9 changes: 8 additions & 1 deletion packages/generator/src/fileCreators/apply-pull/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import CodeBlockWriter from "code-block-writer";
import { Model } from "../types";
import { getUniqueIdentifiers } from "../../helpers/utils";

export function createApplyPullFile(writer: CodeBlockWriter, models: Model[], versionMetaModelName: string) {
export function createApplyPullFile(
writer: CodeBlockWriter,
options: {
models: Model[];
versionMetaModelName: string;
}
) {
const { models, versionMetaModelName } = options;
// Write imports
writer.writeLine(`import type { LogWithStringifiedRecord } from '../server/batch-processor';`);
writer.writeLine(`import { validators, keyPathValidators } from '../validators';`);
Expand Down
9 changes: 6 additions & 3 deletions packages/generator/src/fileCreators/batch-processor/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ function buildAuthorizationPath(

export function createBatchProcessorFile(
writer: CodeBlockWriter,
models: readonly Model[],
prismaClientImport: string,
rootModel: Model
options: {
models: readonly Model[];
prismaClientImport: string;
rootModel: Model;
}
) {
const { models, prismaClientImport, rootModel } = options;
const modelNames = models.map((m) => m.name);

// Write imports
Expand Down
28 changes: 23 additions & 5 deletions packages/generator/src/fileCreators/idb-interface/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import CodeBlockWriter from "code-block-writer";

export function createIDBInterfaceFile(
writer: CodeBlockWriter,
models: DMMF.Datamodel["models"],
prismaClientImport: string,
outboxSync: boolean,
outboxModelName: string,
versionMetaModelName: string
options: {
models: DMMF.Datamodel["models"];
prismaClientImport: string;
outboxSync: boolean;
outboxModelName: string;
versionMetaModelName: string;
hasMigrations?: boolean;
}
) {
const {
models,
prismaClientImport,
outboxSync,
outboxModelName,
versionMetaModelName,
hasMigrations = false,
} = options;
writer.writeLine(`import type { DBSchema } from "idb";`);
writer.writeLine(`import type * as Prisma from "${prismaClientImport}";`);
if (outboxSync) {
Expand Down Expand Up @@ -42,6 +53,13 @@ export function createIDBInterfaceFile(
writer.writeLine(`value: ChangeMetaRecord;`);
});
}

if (hasMigrations) {
writer.writeLine(`_idb_meta: `).block(() => {
writer.writeLine(`key: string;`);
writer.writeLine(`value: string;`);
});
}
});

// Add type definition for OutboxEventRecord
Expand Down
10 changes: 10 additions & 0 deletions packages/generator/src/fileCreators/idb-schema-hash/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import CodeBlockWriter from "code-block-writer";

/**
* Generate the idb-schema-hash.ts file content.
* This file is always regenerated on every `prisma generate` run.
*/
export function createSchemaHashFile(writer: CodeBlockWriter, hash: string) {
writer.writeLine(`// Auto-generated by idb-client-generator — always regenerated`);
writer.writeLine(`export const IDB_SCHEMA_HASH = ${JSON.stringify(hash)};`);
}
9 changes: 6 additions & 3 deletions packages/generator/src/fileCreators/idb-utils/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ import { addAreUint8ArraysEqualHelper } from "./helpers/areUint8ArraysEqual";

export function createUtilsFile(
writer: CodeBlockWriter,
models: readonly Model[],
prismaClientImport: string,
outboxSync: boolean = false
options: {
models: readonly Model[];
prismaClientImport: string;
outboxSync?: boolean;
}
) {
const { models, prismaClientImport, outboxSync = false } = options;
writer.writeLine(`import type { IDBPTransaction, StoreNames } from "idb";`);
writer.writeLine(`import type { PrismaIDBSchema } from "./idb-interface";`);
writer.writeLine(`import type { Prisma } from "${prismaClientImport}";`);
Expand Down
12 changes: 11 additions & 1 deletion packages/generator/src/fileCreators/index/create-client-index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import type CodeBlockWriter from "code-block-writer";

export function createClientIndexFile(writer: CodeBlockWriter, outboxSync: boolean) {
export function createClientIndexFile(
writer: CodeBlockWriter,
options: {
outboxSync: boolean;
hasMigrations?: boolean;
}
) {
const { outboxSync, hasMigrations = false } = options;
writer.writeLine(`export * from './prisma-idb-client';`);
writer.writeLine(`export * from './idb-interface';`);
writer.writeLine(`export * from './idb-utils';`);
if (outboxSync) {
writer.writeLine(`export * from './apply-pull';`);
}
if (hasMigrations) {
writer.writeLine(`export * from './idb-schema-hash';`);
}
}
Loading
Loading