{"version":3,"sources":["../../../../../src/orm/adapters/json/index.ts"],"sourcesContent":["import { open, readFile, rename, unlink, writeFile } from 'node:fs/promises'\n\nimport { v } from 'valleyed'\n\nimport { configurable } from '../../../utilities/configurable'\nimport type { FilterGroup } from '../../filter'\nimport type { DiscoveredSchema } from '../../migrations/introspection-types'\nimport type { AddFieldChange, AddForeignKeyChange, AddIndexChange, AnyFieldSpec, CreateTableChange, DropFieldChange, DropForeignKeyChange, DropIndexChange, DropTableChange, ModifyFieldChange, RenameFieldChange, RenameTableChange } from '../../migrations/types'\nimport { OrmAdapter, type AggregateSpec } from '../../orm-adapter'\nimport type { IterationQueryOptions, QueryOptions } from '../../query-options'\nimport type { AnySchema } from '../../schema'\nimport type { AnyUpdateOp } from '../../updates'\nimport { InMemoryAdapter, type InMemoryRepoConfig } from '../in-memory'\n\nexport type JsonAdapterConfig = InMemoryRepoConfig\n\nconst jsonConnectionPipe = () =>\n\tv.object({\n\t\tfilePath: v.string(),\n\t})\n\nexport class JsonAdapter extends configurable(jsonConnectionPipe, OrmAdapter) {\n\treadonly schemaConfigPipe = v.object({ table: v.string() })\n\n\treadonly #inMemory = InMemoryAdapter.create({})\n\n\treadonly supportedFieldTypes = this.#inMemory.supportedFieldTypes\n\treadonly queryableOps = this.#inMemory.queryableOps\n\treadonly updateOps = this.#inMemory.updateOps\n\treadonly aggregateOps = this.#inMemory.aggregateOps\n\n\t#writeQueue: Promise<void> = Promise.resolve()\n\n\tprotected constructor(config: typeof JsonAdapter.Config) {\n\t\tsuper(config)\n\t}\n\n\tget stores() {\n\t\treturn this.#inMemory.stores\n\t}\n\n\t#serialize(): string {\n\t\tconst obj: Record<string, unknown> = {}\n\n\t\tconst migrations = [...this.#inMemory.migrations.values()]\n\t\tif (migrations.length > 0) obj['__migrations'] = migrations\n\n\t\tconst tables: Record<string, unknown> = {}\n\t\tfor (const [name, meta] of this.#inMemory.tables.entries()) {\n\t\t\ttables[name] = { pk: meta.pk, fields: Object.fromEntries(meta.fields.entries()) }\n\t\t}\n\t\tif (Object.keys(tables).length > 0) obj['__tables'] = tables\n\n\t\tconst indexes: Record<string, unknown> = {}\n\t\tfor (const [name, meta] of this.#inMemory.indexes.entries()) {\n\t\t\tindexes[name] = { table: meta.table, on: [...meta.on], unique: meta.unique }\n\t\t}\n\t\tif (Object.keys(indexes).length > 0) obj['__indexes'] = indexes\n\n\t\tconst foreignKeys: Record<string, unknown> = {}\n\t\tfor (const [name, meta] of this.#inMemory.foreignKeys.entries()) {\n\t\t\tforeignKeys[name] = {\n\t\t\t\ttable: meta.table,\n\t\t\t\ton: meta.on,\n\t\t\t\treferences: meta.references,\n\t\t\t\t...(meta.onDelete ? { onDelete: meta.onDelete } : {}),\n\t\t\t\t...(meta.onUpdate ? { onUpdate: meta.onUpdate } : {}),\n\t\t\t}\n\t\t}\n\t\tif (Object.keys(foreignKeys).length > 0) obj['__foreignKeys'] = foreignKeys\n\n\t\tfor (const [name, store] of this.stores.entries()) {\n\t\t\tconst records: Record<string, Record<string, unknown>> = {}\n\t\t\tfor (const [pk, doc] of store.entries()) {\n\t\t\t\trecords[pk] = doc\n\t\t\t}\n\t\t\tobj[name] = records\n\t\t}\n\n\t\treturn JSON.stringify(obj)\n\t}\n\n\tasync #atomicWrite(): Promise<void> {\n\t\tconst data = this.#serialize()\n\t\tconst tmpPath = this.config.filePath + '.tmp.' + process.pid + '.' + Date.now()\n\t\tawait writeFile(tmpPath, data, 'utf-8')\n\t\tawait rename(tmpPath, this.config.filePath)\n\t}\n\n\t#persistToDisk(): Promise<void> {\n\t\tconst next = this.#writeQueue.then(() => this.#atomicWrite())\n\t\tthis.#writeQueue = next.catch(() => {})\n\t\treturn next\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tlet raw: string\n\t\ttry {\n\t\t\traw = await readFile(this.config.filePath, 'utf-8')\n\t\t} catch {\n\t\t\treturn\n\t\t}\n\t\tconst data = JSON.parse(raw) as Record<string, unknown>\n\n\t\tthis.#inMemory.migrations.clear()\n\t\tif (Array.isArray(data['__migrations'])) {\n\t\t\tfor (const m of data['__migrations'] as Array<{ id: string; appliedAt: number }>) {\n\t\t\t\tthis.#inMemory.migrations.set(m.id, { id: m.id, appliedAt: m.appliedAt })\n\t\t\t}\n\t\t}\n\n\t\tthis.#inMemory.tables.clear()\n\t\tif (data['__tables'] && typeof data['__tables'] === 'object') {\n\t\t\tfor (const [name, meta] of Object.entries(data['__tables'] as Record<string, any>)) {\n\t\t\t\tconst fields = new Map<string, AnyFieldSpec>()\n\t\t\t\tif (meta.fields) {\n\t\t\t\t\tfor (const [fieldName, fspec] of Object.entries(meta.fields as Record<string, AnyFieldSpec>)) {\n\t\t\t\t\t\tfields.set(fieldName, fspec)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.#inMemory.tables.set(name, { pk: meta.pk, fields })\n\t\t\t}\n\t\t}\n\n\t\tthis.#inMemory.indexes.clear()\n\t\tif (data['__indexes'] && typeof data['__indexes'] === 'object') {\n\t\t\tfor (const [name, meta] of Object.entries(data['__indexes'] as Record<string, any>)) {\n\t\t\t\tthis.#inMemory.indexes.set(name, { table: meta.table, on: meta.on, unique: meta.unique })\n\t\t\t}\n\t\t}\n\n\t\tthis.#inMemory.foreignKeys.clear()\n\t\tif (data['__foreignKeys'] && typeof data['__foreignKeys'] === 'object') {\n\t\t\tfor (const [name, meta] of Object.entries(data['__foreignKeys'] as Record<string, any>)) {\n\t\t\t\tthis.#inMemory.foreignKeys.set(name, meta)\n\t\t\t}\n\t\t}\n\n\t\tthis.stores.clear()\n\t\tfor (const [name, records] of Object.entries(data)) {\n\t\t\tif (name.startsWith('__')) continue\n\t\t\tconst store = new Map<string, Record<string, unknown>>()\n\t\t\tfor (const [pk, doc] of Object.entries(records as Record<string, Record<string, unknown>>)) {\n\t\t\t\tstore.set(pk, doc)\n\t\t\t}\n\t\t\tthis.stores.set(name, store)\n\t\t}\n\t}\n\n\tasync disconnect(): Promise<void> {\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync findByPk(schema: AnySchema, config: unknown, pk: unknown) {\n\t\treturn this.#inMemory.findByPk(schema, config, pk)\n\t}\n\n\tasync createMany(schema: AnySchema, config: unknown, data: Record<string, unknown>[]) {\n\t\tconst result = await this.#inMemory.createMany(schema, config, data)\n\t\tawait this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync updateByPk(schema: AnySchema, config: unknown, pk: unknown, ops: AnyUpdateOp[]) {\n\t\tconst result = await this.#inMemory.updateByPk(schema, config, pk, ops)\n\t\tif (result) await this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync deleteByPk(schema: AnySchema, config: unknown, pk: unknown) {\n\t\tconst result = await this.#inMemory.deleteByPk(schema, config, pk)\n\t\tif (result) await this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync findMany(schema: AnySchema, config: unknown, group: FilterGroup, options?: QueryOptions) {\n\t\treturn this.#inMemory.findMany(schema, config, group, options)\n\t}\n\n\tasync count(schema: AnySchema, config: unknown, group: FilterGroup) {\n\t\treturn this.#inMemory.count(schema, config, group)\n\t}\n\n\titerateMany(schema: AnySchema, config: unknown, group: FilterGroup, options?: IterationQueryOptions) {\n\t\treturn this.#inMemory.iterateMany(schema, config, group, options)\n\t}\n\n\tasync updateMany(schema: AnySchema, config: unknown, group: FilterGroup, data: Record<string, unknown>) {\n\t\tconst result = await this.#inMemory.updateMany(schema, config, group, data)\n\t\tif (result.length) await this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync deleteMany(schema: AnySchema, config: unknown, filter: FilterGroup) {\n\t\tconst result = await this.#inMemory.deleteMany(schema, config, filter)\n\t\tif (result.length) await this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync upsertOne(schema: AnySchema, config: unknown, filter: FilterGroup, create: Record<string, unknown>, ops: AnyUpdateOp[]) {\n\t\tconst result = await this.#inMemory.upsertOne(schema, config, filter, create, ops)\n\t\tawait this.#persistToDisk()\n\t\treturn result\n\t}\n\n\tasync aggregate(schema: AnySchema, config: unknown, spec: AggregateSpec) {\n\t\treturn this.#inMemory.aggregate(schema, config, spec)\n\t}\n\n\tasync session<T>(fn: () => Promise<T>): Promise<T> {\n\t\treturn this.#inMemory.session(async () => {\n\t\t\tconst result = await fn()\n\t\t\tawait this.#persistToDisk()\n\t\t\treturn result\n\t\t})\n\t}\n\n\tasync loadMigrations(): Promise<{ id: string; appliedAt: number }[]> {\n\t\tawait this.connect()\n\t\treturn this.#inMemory.loadMigrations()\n\t}\n\n\tasync recordMigration(id: string, appliedAt: number): Promise<void> {\n\t\tawait this.#inMemory.recordMigration(id, appliedAt)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync acquireMigrationLock<T>(fn: () => Promise<T>): Promise<T> {\n\t\tconst lockPath = this.config.filePath + '.lock'\n\t\tconst deadline = Date.now() + 30_000\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\tconst handle = await open(lockPath, 'wx')\n\t\t\t\tawait handle.close()\n\t\t\t\tbreak\n\t\t\t} catch (err: any) {\n\t\t\t\tif (err.code !== 'EEXIST') throw err\n\t\t\t\tif (Date.now() > deadline) throw new Error('Timed out waiting for migration lock')\n\t\t\t\tawait new Promise((r) => setTimeout(r, 50))\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\treturn await fn()\n\t\t} finally {\n\t\t\tawait unlink(lockPath).catch(() => {})\n\t\t}\n\t}\n\n\tasync applyCreateTable(change: CreateTableChange<any>): Promise<void> {\n\t\tawait this.#inMemory.applyCreateTable(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyDropTable(change: DropTableChange): Promise<void> {\n\t\tawait this.#inMemory.applyDropTable(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyAddField(change: AddFieldChange<any>): Promise<void> {\n\t\tawait this.#inMemory.applyAddField(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyDropField(change: DropFieldChange): Promise<void> {\n\t\tawait this.#inMemory.applyDropField(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyModifyField(change: ModifyFieldChange<any>): Promise<void> {\n\t\tawait this.#inMemory.applyModifyField(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyRenameTable(change: RenameTableChange): Promise<void> {\n\t\tawait this.#inMemory.applyRenameTable(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyRenameField(change: RenameFieldChange): Promise<void> {\n\t\tawait this.#inMemory.applyRenameField(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyAddIndex(change: AddIndexChange): Promise<void> {\n\t\tawait this.#inMemory.applyAddIndex(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyDropIndex(change: DropIndexChange): Promise<void> {\n\t\tawait this.#inMemory.applyDropIndex(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyAddForeignKey(change: AddForeignKeyChange): Promise<void> {\n\t\tawait this.#inMemory.applyAddForeignKey(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync applyDropForeignKey(change: DropForeignKeyChange): Promise<void> {\n\t\tawait this.#inMemory.applyDropForeignKey(change)\n\t\tawait this.#persistToDisk()\n\t}\n\n\tasync introspect(): Promise<DiscoveredSchema[]> {\n\t\treturn this.#inMemory.introspect()\n\t}\n}\n\nif (import.meta.vitest) {\n\tconst { describe, test, expect, beforeEach, afterEach } = import.meta.vitest\n\tconst { FilterGroup } = await import('../../filter')\n\tconst { OrderBy } = await import('../../query-options')\n\tconst { Schema } = await import('../../schema')\n\tconst { IncOp, PatchOp, PullOp, PushOp } = await import('../../updates')\n\tconst { v } = await import('valleyed')\n\tconst { mkdtemp, rm } = await import('node:fs/promises')\n\tconst { tmpdir } = await import('node:os')\n\tconst { join } = await import('node:path')\n\tconst { Migrator } = await import('../../migrations/migrator')\n\tconst { Repo } = await import('../../repo/repo')\n\tconst { OrmMigrationError } = await import('../../errors/migration')\n\ttype Migration<A extends import('../base').OrmAdapterLike<any>> = import('../../migrations/types').Migration<A>\n\n\tlet tmpDir: string\n\tlet filePath: string\n\n\tbeforeEach(async () => {\n\t\ttmpDir = await mkdtemp(join(tmpdir(), 'json-adapter-'))\n\t\tfilePath = join(tmpDir, 'test.json')\n\t})\n\n\tafterEach(async () => {\n\t\tawait rm(tmpDir, { recursive: true, force: true })\n\t})\n\n\tdescribe('json adapter — class construction', () => {\n\t\ttest('JsonAdapter.create({ filePath }) produces a working adapter', () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\texpect(adapter).toBeInstanceOf(JsonAdapter)\n\t\t\texpect(adapter.schemaConfigPipe).toBeDefined()\n\t\t\texpect(adapter.supportedFieldTypes).toEqual(['string', 'number', 'boolean', 'null', 'object', 'array', 'date'])\n\t\t})\n\n\t\ttest('auto-wired Instance hooks register connect/disconnect keyed by class', async () => {\n\t\t\tconst { Instance: Inst } = await import('../../../instance')\n\t\t\tconst onSpy = (await import('vitest')).vi.spyOn(Inst, 'on').mockImplementation(() => {})\n\n\t\t\tJsonAdapter.create({ filePath })\n\n\t\t\texpect(onSpy).toHaveBeenCalledWith('start', expect.any(Function), expect.objectContaining({ class: JsonAdapter }))\n\t\t\texpect(onSpy).toHaveBeenCalledWith('close', expect.any(Function), expect.objectContaining({ class: JsonAdapter }))\n\n\t\t\tonSpy.mockRestore()\n\t\t})\n\t})\n\n\tdescribe('json adapter — surface parity with in-memory', () => {\n\t\ttest('CRUD: create, find, update, delete round-trip', async () => {\n\t\t\tconst schema = Schema.from('users')\n\t\t\t\t.pk('id', v.string(), () => 'u')\n\t\t\t\t.field('name', v.string())\n\t\t\t\t.field('age', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tconst use = adapter.use(schema, { table: 'users' })\n\n\t\t\tconst created = await use.createMany([\n\t\t\t\t{ id: 'u1', name: 'Alice', age: 30 },\n\t\t\t\t{ id: 'u2', name: 'Bob', age: 20 },\n\t\t\t])\n\t\t\texpect(created).toHaveLength(2)\n\n\t\t\tconst found = await use.findOne(FilterGroup.create().eq('id', 'u1'))\n\t\t\texpect(found).toEqual({ id: 'u1', name: 'Alice', age: 30 })\n\n\t\t\tconst many = await use.findMany(FilterGroup.create().gt('age', 19), {\n\t\t\t\torderBy: [new OrderBy('age', 'asc')],\n\t\t\t})\n\t\t\texpect(many).toEqual([\n\t\t\t\t{ id: 'u2', name: 'Bob', age: 20 },\n\t\t\t\t{ id: 'u1', name: 'Alice', age: 30 },\n\t\t\t])\n\n\t\t\tawait use.updateOne(FilterGroup.create().eq('id', 'u1'), { age: 31 })\n\t\t\tconst updated = await use.findOne(FilterGroup.create().eq('id', 'u1'))\n\t\t\texpect(updated?.age).toBe(31)\n\n\t\t\tconst deleted = await use.deleteOne(FilterGroup.create().eq('id', 'u2'))\n\t\t\texpect(deleted).toEqual({ id: 'u2', name: 'Bob', age: 20 })\n\n\t\t\tconst remaining = await use.findMany(FilterGroup.create())\n\t\t\texpect(remaining).toHaveLength(1)\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('supports nested filters, ordering, select, offset and limit', async () => {\n\t\t\tconst schema = Schema.from('users')\n\t\t\t\t.pk('id', v.string(), () => 'u')\n\t\t\t\t.field('name', v.string())\n\t\t\t\t.field('age', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'users' })\n\n\t\t\tawait use.createMany([\n\t\t\t\t{ id: 'u1', name: 'Alice', age: 30 },\n\t\t\t\t{ id: 'u2', name: 'Bob', age: 20 },\n\t\t\t\t{ id: 'u3', name: 'Carol', age: 40 },\n\t\t\t])\n\n\t\t\tconst builtGroup = FilterGroup.create().and([\n\t\t\t\t(q) => q.gt('age', 19),\n\t\t\t\t(q) => q.or([(g) => g.eq('name', 'Alice'), (g) => g.eq('name', 'Carol')]),\n\t\t\t])\n\t\t\tconst options = { orderBy: [new OrderBy('age', 'desc')], offset: 1, limit: 1, select: ['id', 'name'] as const }\n\t\t\tconst rows = await use.findMany(builtGroup, options)\n\t\t\texpect(rows).toEqual([{ id: 'u1', name: 'Alice' }])\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('count delegates to the in-memory store and persists separately from query options', async () => {\n\t\t\tconst schema = Schema.from('count_users')\n\t\t\t\t.pk('id', v.string(), () => 'u')\n\t\t\t\t.field('name', v.string())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'count_users' })\n\t\t\tawait use.createMany([\n\t\t\t\t{ id: 'u1', name: 'Alice' },\n\t\t\t\t{ id: 'u2', name: 'Bob' },\n\t\t\t\t{ id: 'u3', name: 'Alice' },\n\t\t\t])\n\n\t\t\tawait expect(use.count(FilterGroup.create().eq('name', 'Alice'))).resolves.toBe(2)\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('iterateMany with batchSize matches findMany through in-memory delegation', async () => {\n\t\t\tconst schema = Schema.from('json_iter_users')\n\t\t\t\t.pk('id', v.string(), () => 'u')\n\t\t\t\t.field('name', v.string())\n\t\t\t\t.field('age', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'json_iter_users' })\n\t\t\tawait use.createMany([\n\t\t\t\t{ id: 'u1', name: 'Alice', age: 30 },\n\t\t\t\t{ id: 'u2', name: 'Bob', age: 20 },\n\t\t\t\t{ id: 'u3', name: 'Carol', age: 40 },\n\t\t\t\t{ id: 'u4', name: 'Dan', age: 50 },\n\t\t\t])\n\n\t\t\tconst filter = FilterGroup.create().gt('age', 19)\n\t\t\tconst options = {\n\t\t\t\torderBy: [new OrderBy('age', 'desc')],\n\t\t\t\toffset: 1,\n\t\t\t\tlimit: 2,\n\t\t\t\tselect: ['id', 'name'],\n\t\t\t}\n\t\t\tconst expected = await use.findMany(filter, options)\n\t\t\tconst rows: Record<string, unknown>[] = []\n\t\t\tfor await (const row of use.iterateMany(filter, { ...options, batchSize: 2 })) {\n\t\t\t\trows.push(row)\n\t\t\t}\n\t\t\texpect(rows).toEqual(expected)\n\t\t\texpect(rows).toEqual([\n\t\t\t\t{ id: 'u3', name: 'Carol' },\n\t\t\t\t{ id: 'u1', name: 'Alice' },\n\t\t\t])\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('supports update operators and rollback on failed session', async () => {\n\t\t\tconst schema = Schema.from('docs')\n\t\t\t\t.pk('id', v.string(), () => 'd1')\n\t\t\t\t.field('count', v.number())\n\t\t\t\t.field('tags', v.array(v.string()))\n\t\t\t\t.field('meta', v.object({ a: v.number() }))\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'docs' })\n\n\t\t\tawait use.createOne({ id: 'd1', count: 1, tags: ['x'], meta: { a: 1 } })\n\n\t\t\tawait adapter.session(async () => {\n\t\t\t\tawait use.updateOne(FilterGroup.create().eq('id', 'd1'), {\n\t\t\t\t\tcount: new IncOp('count', 2),\n\t\t\t\t\ttags: new PushOp('tags', 'y'),\n\t\t\t\t\tmeta: new PatchOp('meta', { a: 9 }),\n\t\t\t\t})\n\t\t\t})\n\n\t\t\tawait expect(\n\t\t\t\tadapter.session(async () => {\n\t\t\t\t\tawait use.updateOne(FilterGroup.create().eq('id', 'd1'), { tags: new PullOp('tags', 'x') })\n\t\t\t\t\tthrow new Error('boom')\n\t\t\t\t}),\n\t\t\t).rejects.toThrow('boom')\n\n\t\t\tconst row = await use.findOne(FilterGroup.create().eq('id', 'd1'))\n\t\t\texpect(row).toEqual({ id: 'd1', count: 3, tags: ['x', 'y'], meta: { a: 9 } })\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('upsertOne inserts when missing and updates when existing', async () => {\n\t\t\tconst schema = Schema.from('items')\n\t\t\t\t.pk('id', v.string(), () => 'i')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'items' })\n\n\t\t\tconst inserted = await use.upsertOne(FilterGroup.create().eq('id', 'i1'), { id: 'i1', val: 10 }, [])\n\t\t\texpect(inserted).toEqual({ id: 'i1', val: 10 })\n\n\t\t\tconst updated = await use.upsertOne(FilterGroup.create().eq('id', 'i1'), { id: 'i1', val: 10 }, [new IncOp('val', 5)])\n\t\t\texpect(updated).toEqual({ id: 'i1', val: 15 })\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — persistence', () => {\n\t\ttest('state persists across adapter restarts', async () => {\n\t\t\tconst schema = Schema.from('users')\n\t\t\t\t.pk('id', v.string(), () => 'u')\n\t\t\t\t.field('name', v.string())\n\t\t\t\t.build()\n\n\t\t\tconst a1 = JsonAdapter.create({ filePath })\n\t\t\tawait a1.connect()\n\t\t\tconst use1 = a1.use(schema, { table: 'users' })\n\t\t\tawait use1.createMany([\n\t\t\t\t{ id: 'u1', name: 'Alice' },\n\t\t\t\t{ id: 'u2', name: 'Bob' },\n\t\t\t])\n\t\t\tawait a1.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst use2 = a2.use(schema, { table: 'users' })\n\t\t\tconst rows = await use2.findMany(FilterGroup.create())\n\t\t\texpect(rows).toHaveLength(2)\n\t\t\texpect(rows.map((r) => r.name).sort()).toEqual(['Alice', 'Bob'])\n\t\t\tawait a2.disconnect()\n\t\t})\n\n\t\ttest('failed session does not persist rolled-back state to disk', async () => {\n\t\t\tconst schema = Schema.from('docs')\n\t\t\t\t.pk('id', v.string(), () => 'd')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst a1 = JsonAdapter.create({ filePath })\n\t\t\tawait a1.connect()\n\t\t\tconst use1 = a1.use(schema, { table: 'docs' })\n\t\t\tawait use1.createOne({ id: 'd1', val: 1 })\n\t\t\tawait a1.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst use2 = a2.use(schema, { table: 'docs' })\n\t\t\tawait expect(\n\t\t\t\ta2.session(async () => {\n\t\t\t\t\tawait use2.updateOne(FilterGroup.create().eq('id', 'd1'), { val: 999 })\n\t\t\t\t\tthrow new Error('rollback')\n\t\t\t\t}),\n\t\t\t).rejects.toThrow('rollback')\n\t\t\tawait a2.disconnect()\n\n\t\t\tconst a3 = JsonAdapter.create({ filePath })\n\t\t\tawait a3.connect()\n\t\t\tconst use3 = a3.use(schema, { table: 'docs' })\n\t\t\tconst row = await use3.findOne(FilterGroup.create().eq('id', 'd1'))\n\t\t\texpect(row?.val).toBe(1)\n\t\t\tawait a3.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — atomic writes', () => {\n\t\ttest('file is valid JSON after every write', async () => {\n\t\t\tconst { readFile: rf } = await import('node:fs/promises')\n\t\t\tconst schema = Schema.from('items')\n\t\t\t\t.pk('id', v.string(), () => 'i')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'items' })\n\n\t\t\tfor (let i = 0; i < 10; i++) {\n\t\t\t\tawait use.createOne({ id: `i${i}`, val: i })\n\t\t\t\tconst raw = await rf(filePath, 'utf-8')\n\t\t\t\texpect(() => JSON.parse(raw)).not.toThrow()\n\t\t\t}\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('no .tmp files remain after writes complete', async () => {\n\t\t\tconst { readdir } = await import('node:fs/promises')\n\t\t\tconst schema = Schema.from('items')\n\t\t\t\t.pk('id', v.string(), () => 'i')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'items' })\n\n\t\t\tfor (let i = 0; i < 5; i++) {\n\t\t\t\tawait use.createOne({ id: `i${i}`, val: i })\n\t\t\t}\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst files = await readdir(tmpDir)\n\t\t\tconst tmpFiles = files.filter((f) => f.includes('.tmp.'))\n\t\t\texpect(tmpFiles).toHaveLength(0)\n\t\t})\n\t})\n\n\tdescribe('json adapter — aggregate delegation', () => {\n\t\tconst orderSchema = Schema.from('orders')\n\t\t\t.pk('id', v.string(), () => 'o')\n\t\t\t.field('amount', v.number())\n\t\t\t.field('region', v.string())\n\t\t\t.build()\n\n\t\tconst orderSeed = [\n\t\t\t{ id: 'o1', amount: 100, region: 'us' },\n\t\t\t{ id: 'o2', amount: 200, region: 'eu' },\n\t\t\t{ id: 'o3', amount: 150, region: 'us' },\n\t\t]\n\n\t\tasync function makeSeededAdapter() {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(orderSchema, { table: 'orders' })\n\t\t\tawait use.createMany(orderSeed)\n\t\t\treturn adapter\n\t\t}\n\n\t\ttest('aggregateOps matches in-memory adapter', () => {\n\t\t\tconst json = JsonAdapter.create({ filePath })\n\t\t\tconst inMem = InMemoryAdapter.create({})\n\t\t\texpect(json.aggregateOps).toEqual(inMem.aggregateOps)\n\t\t\texpect(json.aggregateOps).toEqual(['count', 'countDistinct', 'sum', 'avg', 'min', 'max'])\n\t\t})\n\n\t\ttest('count returns identical result to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\taggregates: [{ fn: 'count', alias: 'total' }],\n\t\t\t\tgroupBy: [],\n\t\t\t})\n\t\t\texpect(result).toEqual([{ total: 3 }])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('countDistinct returns identical result to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\taggregates: [{ fn: 'countDistinct', field: 'region', alias: 'uniqueRegions' }],\n\t\t\t\tgroupBy: [],\n\t\t\t})\n\t\t\texpect(result).toEqual([{ uniqueRegions: 2 }])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('sum, avg, min, max return identical results to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\taggregates: [\n\t\t\t\t\t{ fn: 'sum', field: 'amount', alias: 'totalAmount' },\n\t\t\t\t\t{ fn: 'avg', field: 'amount', alias: 'avgAmount' },\n\t\t\t\t\t{ fn: 'min', field: 'amount', alias: 'minAmount' },\n\t\t\t\t\t{ fn: 'max', field: 'amount', alias: 'maxAmount' },\n\t\t\t\t],\n\t\t\t\tgroupBy: [],\n\t\t\t})\n\t\t\texpect(result).toEqual([{ totalAmount: 450, avgAmount: 150, minAmount: 100, maxAmount: 200 }])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('groupBy returns identical results to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\taggregates: [\n\t\t\t\t\t{ fn: 'count', alias: 'cnt' },\n\t\t\t\t\t{ fn: 'sum', field: 'amount', alias: 'total' },\n\t\t\t\t],\n\t\t\t\tgroupBy: ['region'],\n\t\t\t})\n\t\t\tconst sorted = result.sort((a, b) => String(a.region).localeCompare(String(b.region)))\n\t\t\texpect(sorted).toEqual([\n\t\t\t\t{ region: 'eu', cnt: 1, total: 200 },\n\t\t\t\t{ region: 'us', cnt: 2, total: 250 },\n\t\t\t])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('where pre-filter returns identical results to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\twhere: FilterGroup.create().gt('amount', 100),\n\t\t\t\taggregates: [{ fn: 'count', alias: 'cnt' }],\n\t\t\t\tgroupBy: [],\n\t\t\t})\n\t\t\texpect(result).toEqual([{ cnt: 2 }])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('having post-filter returns identical results to in-memory', async () => {\n\t\t\tconst adapter = await makeSeededAdapter()\n\t\t\tconst result = await adapter.aggregate(orderSchema, { table: 'orders' }, {\n\t\t\t\taggregates: [{ fn: 'count', alias: 'cnt' }],\n\t\t\t\tgroupBy: ['region'],\n\t\t\t\thaving: FilterGroup.create().gt('cnt', 1),\n\t\t\t})\n\t\t\texpect(result).toEqual([{ region: 'us', cnt: 2 }])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('aggregate delegates to same in-memory instance used by CRUD', async () => {\n\t\t\tconst schema = Schema.from('items')\n\t\t\t\t.pk('id', v.string(), () => 'i')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'items' })\n\n\t\t\tawait use.createMany([\n\t\t\t\t{ id: 'i1', val: 10 },\n\t\t\t\t{ id: 'i2', val: 20 },\n\t\t\t])\n\n\t\t\tconst spec: AggregateSpec = {\n\t\t\t\taggregates: [{ fn: 'sum', field: 'val', alias: 'total' }],\n\t\t\t\tgroupBy: [],\n\t\t\t}\n\t\t\tconst result = await adapter.aggregate(schema, { table: 'items' }, spec)\n\t\t\texpect(result).toEqual([{ total: 30 }])\n\n\t\t\tawait use.createOne({ id: 'i3', val: 30 })\n\t\t\tconst result2 = await adapter.aggregate(schema, { table: 'items' }, spec)\n\t\t\texpect(result2).toEqual([{ total: 60 }])\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — concurrent writes serialize', () => {\n\t\ttest('parallel writes from same process all persist', async () => {\n\t\t\tconst schema = Schema.from('items')\n\t\t\t\t.pk('id', v.string(), () => 'i')\n\t\t\t\t.field('val', v.number())\n\t\t\t\t.build()\n\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tconst use = adapter.use(schema, { table: 'items' })\n\n\t\t\tawait Promise.all(Array.from({ length: 20 }, (_, i) => use.createOne({ id: `i${i}`, val: i })))\n\n\t\t\tconst rows = await use.findMany(FilterGroup.create())\n\t\t\texpect(rows).toHaveLength(20)\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst use2 = a2.use(schema, { table: 'items' })\n\t\t\tconst reloaded = await use2.findMany(FilterGroup.create())\n\t\t\texpect(reloaded).toHaveLength(20)\n\t\t\tawait a2.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — migration storage', () => {\n\t\ttest('recordMigration + loadMigrations round-trip', async () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tawait adapter.recordMigration('m-001', 1000)\n\t\t\tawait adapter.recordMigration('m-002', 2000)\n\n\t\t\tconst loaded = await adapter.loadMigrations()\n\t\t\texpect(loaded).toHaveLength(2)\n\t\t\texpect(loaded).toEqual([\n\t\t\t\t{ id: 'm-001', appliedAt: 1000 },\n\t\t\t\t{ id: 'm-002', appliedAt: 2000 },\n\t\t\t])\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('migration tracker persists across adapter restarts', async () => {\n\t\t\tconst a1 = JsonAdapter.create({ filePath })\n\t\t\tawait a1.connect()\n\t\t\tawait a1.recordMigration('m-001', 1000)\n\t\t\tawait a1.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst loaded = await a2.loadMigrations()\n\t\t\texpect(loaded).toEqual([{ id: 'm-001', appliedAt: 1000 }])\n\t\t\tawait a2.disconnect()\n\t\t})\n\n\t\ttest('__migrations key in JSON file stores tracker data', async () => {\n\t\t\tconst { readFile: rf } = await import('node:fs/promises')\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tawait adapter.recordMigration('m-001', 1000)\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst raw = JSON.parse(await rf(filePath, 'utf-8'))\n\t\t\texpect(raw['__migrations']).toEqual([{ id: 'm-001', appliedAt: 1000 }])\n\t\t})\n\t})\n\n\tdescribe('json adapter — apply* methods', () => {\n\t\ttest('applyCreateTable persists table metadata', async () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tawait adapter.applyCreateTable({\n\t\t\t\tkind: 'createTable',\n\t\t\t\tname: 'users',\n\t\t\t\tpk: { name: 'id', type: 'string' },\n\t\t\t\tfields: [{ name: 'email', type: 'string', unique: true }],\n\t\t\t})\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst schemas = await a2.introspect()\n\t\t\texpect(schemas).toHaveLength(1)\n\t\t\texpect(schemas[0].name).toBe('users')\n\t\t\texpect(schemas[0].pk).toEqual({ name: 'id', type: 'string' })\n\t\t\texpect(schemas[0].fields).toEqual([{ name: 'email', type: 'string', nullable: false, unique: true }])\n\t\t\tawait a2.disconnect()\n\t\t})\n\n\t\ttest('applyAddIndex and applyDropIndex persist across restarts', async () => {\n\t\t\tconst a1 = JsonAdapter.create({ filePath })\n\t\t\tawait a1.connect()\n\t\t\tawait a1.applyCreateTable({ kind: 'createTable', name: 'users', pk: { name: 'id', type: 'string' }, fields: [] })\n\t\t\tawait a1.applyAddIndex({ kind: 'addIndex', table: 'users', on: ['email'], unique: true })\n\t\t\tawait a1.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst schemas = await a2.introspect()\n\t\t\texpect(schemas[0].indexes).toEqual([{ name: 'users_email_idx', on: ['email'], unique: true }])\n\t\t\tawait a2.applyDropIndex({ kind: 'dropIndex', name: 'users_email_idx' })\n\t\t\tawait a2.disconnect()\n\n\t\t\tconst a3 = JsonAdapter.create({ filePath })\n\t\t\tawait a3.connect()\n\t\t\tconst schemas2 = await a3.introspect()\n\t\t\texpect(schemas2[0].indexes).toEqual([])\n\t\t\tawait a3.disconnect()\n\t\t})\n\n\t\ttest('applyAddForeignKey and applyDropForeignKey persist across restarts', async () => {\n\t\t\tconst a1 = JsonAdapter.create({ filePath })\n\t\t\tawait a1.connect()\n\t\t\tawait a1.applyCreateTable({ kind: 'createTable', name: 'users', pk: { name: 'id', type: 'string' }, fields: [] })\n\t\t\tawait a1.applyCreateTable({ kind: 'createTable', name: 'posts', pk: { name: 'id', type: 'string' }, fields: [] })\n\t\t\tawait a1.applyAddForeignKey({ kind: 'addForeignKey', table: 'posts', on: 'authorId', references: { table: 'users', column: 'id' }, onDelete: 'cascade' })\n\t\t\tawait a1.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst schemas = await a2.introspect()\n\t\t\tconst posts = schemas.find((s) => s.name === 'posts')!\n\t\t\texpect(posts.foreignKeys).toEqual([{\n\t\t\t\tname: 'posts_authorId_fk',\n\t\t\t\ton: 'authorId',\n\t\t\t\treferences: { table: 'users', column: 'id' },\n\t\t\t\tonDelete: 'cascade',\n\t\t\t}])\n\t\t\tawait a2.applyDropForeignKey({ kind: 'dropForeignKey', table: 'posts', name: 'posts_authorId_fk' })\n\t\t\tawait a2.disconnect()\n\n\t\t\tconst a3 = JsonAdapter.create({ filePath })\n\t\t\tawait a3.connect()\n\t\t\tconst schemas2 = await a3.introspect()\n\t\t\tconst posts2 = schemas2.find((s) => s.name === 'posts')!\n\t\t\texpect(posts2.foreignKeys).toEqual([])\n\t\t\tawait a3.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — acquireMigrationLock', () => {\n\t\ttest('file lock serialises concurrent calls', async () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tconst order: string[] = []\n\t\t\tlet resolveGate!: () => void\n\t\t\tconst gate = new Promise<void>((r) => { resolveGate = r })\n\n\t\t\tconst p1 = adapter.acquireMigrationLock(async () => {\n\t\t\t\torder.push('p1-start')\n\t\t\t\tawait gate\n\t\t\t\torder.push('p1-end')\n\t\t\t})\n\t\t\tawait new Promise((r) => setTimeout(r, 100))\n\t\t\tconst p2 = adapter.acquireMigrationLock(async () => {\n\t\t\t\torder.push('p2')\n\t\t\t})\n\n\t\t\tawait new Promise((r) => setTimeout(r, 100))\n\t\t\texpect(order).toEqual(['p1-start'])\n\n\t\t\tresolveGate()\n\t\t\tawait Promise.all([p1, p2])\n\t\t\texpect(order).toEqual(['p1-start', 'p1-end', 'p2'])\n\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('lock file is cleaned up after successful execution', async () => {\n\t\t\tconst { access } = await import('node:fs/promises')\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tawait adapter.acquireMigrationLock(async () => { /* no-op */ })\n\n\t\t\tawait expect(access(filePath + '.lock')).rejects.toThrow()\n\t\t\tawait adapter.disconnect()\n\t\t})\n\n\t\ttest('lock file is cleaned up after failed execution', async () => {\n\t\t\tconst { access } = await import('node:fs/promises')\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tawait expect(\n\t\t\t\tadapter.acquireMigrationLock(async () => { throw new Error('boom') }),\n\t\t\t).rejects.toThrow('boom')\n\n\t\t\tawait expect(access(filePath + '.lock')).rejects.toThrow()\n\t\t\tawait adapter.disconnect()\n\t\t})\n\t})\n\n\tdescribe('json adapter — end-to-end migrations via Migrator', () => {\n\t\tconst UserSchema = Schema.from('users')\n\t\t\t.pk('id', v.string(), () => `u-${Math.random().toString(36).slice(2)}`)\n\t\t\t.field('email', v.string())\n\t\t\t.build()\n\n\t\tfunction makeEnv() {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tconst repo = new Repo({ adapter, resolve: (s) => ({ table: s.name }) })\n\t\t\treturn { adapter, repo }\n\t\t}\n\n\t\ttest('end-to-end migration run covering every declarative variant + execute', async () => {\n\t\t\tconst { adapter, repo } = makeEnv()\n\t\t\tawait adapter.connect()\n\n\t\t\tconst migrations: Migration<typeof adapter>[] = [\n\t\t\t\t{\n\t\t\t\t\tid: '0001-create',\n\t\t\t\t\tchanges: [\n\t\t\t\t\t\t{ kind: 'createTable', name: 'users', pk: { name: 'id', type: 'string' }, fields: [{ name: 'email', type: 'string' }] },\n\t\t\t\t\t\t{ kind: 'createTable', name: 'posts', pk: { name: 'id', type: 'string' }, fields: [{ name: 'title', type: 'string' }, { name: 'authorId', type: 'string' }] },\n\t\t\t\t\t\t{ kind: 'addIndex', table: 'users', on: ['email'], unique: true },\n\t\t\t\t\t\t{ kind: 'addForeignKey', table: 'posts', on: 'authorId', references: { table: 'users', column: 'id' } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: '0002-evolve',\n\t\t\t\t\tchanges: [\n\t\t\t\t\t\t{ kind: 'addField', table: 'users', field: { name: 'age', type: 'number', nullable: true } },\n\t\t\t\t\t\t{ kind: 'modifyField', table: 'users', name: 'email', to: { name: 'email', type: 'string', unique: true, nullable: true } },\n\t\t\t\t\t\t{ kind: 'renameField', table: 'posts', from: 'title', to: 'headline' },\n\t\t\t\t\t\t{ kind: 'renameTable', from: 'posts', to: 'articles' },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: '0003-cleanup',\n\t\t\t\t\tchanges: [\n\t\t\t\t\t\t{ kind: 'dropField', table: 'users', name: 'age' },\n\t\t\t\t\t\t{ kind: 'dropForeignKey', table: 'posts', name: 'posts_authorId_fk' },\n\t\t\t\t\t\t{ kind: 'dropIndex', name: 'users_email_idx' },\n\t\t\t\t\t\t{ kind: 'dropTable', name: 'articles' },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: '0004-seed',\n\t\t\t\t\tchanges: [{\n\t\t\t\t\t\tkind: 'execute',\n\t\t\t\t\t\tup: async (r) => {\n\t\t\t\t\t\t\tawait r.on(UserSchema).one().create({ id: 'seed-1', email: 'test@example.com' })\n\t\t\t\t\t\t},\n\t\t\t\t\t}],\n\t\t\t\t},\n\t\t\t]\n\n\t\t\tconst migrator = Migrator.from(repo, adapter).migrations(migrations).build()\n\t\t\tconst result = await migrator.up()\n\t\t\texpect(result.ran).toEqual(['0001-create', '0002-evolve', '0003-cleanup', '0004-seed'])\n\n\t\t\tconst recorded = await adapter.loadMigrations()\n\t\t\texpect(recorded).toHaveLength(4)\n\n\t\t\tconst row = await repo.on(UserSchema).one().id('seed-1').find()\n\t\t\texpect(row).not.toBeNull()\n\t\t\texpect(row!.email).toBe('test@example.com')\n\n\t\t\t// Verify via re-reading the file\n\t\t\tawait adapter.disconnect()\n\t\t\tconst { adapter: a2, repo: r2 } = makeEnv()\n\t\t\tawait a2.connect()\n\t\t\tconst recorded2 = await a2.loadMigrations()\n\t\t\texpect(recorded2).toHaveLength(4)\n\n\t\t\tconst row2 = await r2.on(UserSchema).one().id('seed-1').find()\n\t\t\texpect(row2!.email).toBe('test@example.com')\n\t\t\tawait a2.disconnect()\n\t\t})\n\n\t\ttest('file lock serialises concurrent migrator.up() runs', async () => {\n\t\t\tconst order: string[] = []\n\t\t\tlet resolveGate!: () => void\n\t\t\tconst gate = new Promise<void>((r) => { resolveGate = r })\n\n\t\t\tconst migrations: Migration<JsonAdapter>[] = [\n\t\t\t\t{\n\t\t\t\t\tid: '0001',\n\t\t\t\t\tchanges: [{\n\t\t\t\t\t\tkind: 'execute',\n\t\t\t\t\t\tup: async () => {\n\t\t\t\t\t\t\torder.push('0001-start')\n\t\t\t\t\t\t\tawait gate\n\t\t\t\t\t\t\torder.push('0001-end')\n\t\t\t\t\t\t},\n\t\t\t\t\t}],\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: '0002',\n\t\t\t\t\tchanges: [{ kind: 'execute', up: async () => { order.push('0002') } }],\n\t\t\t\t},\n\t\t\t]\n\n\t\t\tconst adapter1 = JsonAdapter.create({ filePath })\n\t\t\tawait adapter1.connect()\n\t\t\tconst repo1 = new Repo({ adapter: adapter1, resolve: (s) => ({ table: s.name }) })\n\t\t\tconst migrator1 = Migrator.from(repo1, adapter1).migrations(migrations).build()\n\n\t\t\tconst adapter2 = JsonAdapter.create({ filePath })\n\t\t\tawait adapter2.connect()\n\t\t\tconst repo2 = new Repo({ adapter: adapter2, resolve: (s) => ({ table: s.name }) })\n\t\t\tconst migrator2 = Migrator.from(repo2, adapter2).migrations(migrations).build()\n\n\t\t\tconst p1 = migrator1.up()\n\t\t\tconst p2 = migrator2.up()\n\n\t\t\tawait new Promise((r) => setTimeout(r, 200))\n\t\t\texpect(order).toEqual(['0001-start'])\n\n\t\t\tresolveGate()\n\t\t\tawait Promise.all([p1, p2])\n\n\t\t\texpect(order).toEqual(['0001-start', '0001-end', '0002'])\n\n\t\t\tawait adapter1.disconnect()\n\t\t\tawait adapter2.disconnect()\n\t\t})\n\n\t\ttest('tx:true rollback leaves file unchanged on failure', async () => {\n\t\t\tconst { adapter } = makeEnv()\n\t\t\tawait adapter.connect()\n\n\t\t\tawait adapter.applyCreateTable({ kind: 'createTable', name: 'users', pk: { name: 'id', type: 'string' }, fields: [] })\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst { adapter: a2, repo: r2 } = makeEnv()\n\t\t\tawait a2.connect()\n\n\t\t\tconst m: Migration<typeof a2> = {\n\t\t\t\tid: '0001-will-fail',\n\t\t\t\tchanges: [\n\t\t\t\t\t{ kind: 'addIndex', table: 'users', on: ['email'] },\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: 'execute',\n\t\t\t\t\t\tup: async (r) => {\n\t\t\t\t\t\t\tawait r.on(UserSchema).one().create({ id: 'partial', email: 'fail@test.com' })\n\t\t\t\t\t\t\tthrow new Error('mid-migration boom')\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t}\n\t\t\tconst migrator = Migrator.from(r2, a2).migrations([m]).build()\n\t\t\tawait expect(migrator.up()).rejects.toThrow(OrmMigrationError)\n\t\t\tawait a2.disconnect()\n\n\t\t\tconst { adapter: a3, repo: r3 } = makeEnv()\n\t\t\tawait a3.connect()\n\t\t\tconst recorded = await a3.loadMigrations()\n\t\t\texpect(recorded).toHaveLength(0)\n\t\t\tconst schemas = await a3.introspect()\n\t\t\tconst users = schemas.find((s) => s.name === 'users')!\n\t\t\texpect(users.indexes).toEqual([])\n\t\t\tconst row = await r3.on(UserSchema).one().id('partial').find()\n\t\t\texpect(row).toBeNull()\n\t\t\tawait a3.disconnect()\n\t\t})\n\n\t\ttest('introspect() round-trip: apply* then introspect returns matching descriptors', async () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\n\t\t\tawait adapter.applyCreateTable({\n\t\t\t\tkind: 'createTable',\n\t\t\t\tname: 'users',\n\t\t\t\tpk: { name: 'id', type: 'string' },\n\t\t\t\tfields: [\n\t\t\t\t\t{ name: 'email', type: 'string', unique: true },\n\t\t\t\t\t{ name: 'age', type: 'number', nullable: true },\n\t\t\t\t],\n\t\t\t})\n\t\t\tawait adapter.applyAddIndex({ kind: 'addIndex', table: 'users', on: ['email'], unique: true })\n\t\t\tawait adapter.applyCreateTable({\n\t\t\t\tkind: 'createTable',\n\t\t\t\tname: 'posts',\n\t\t\t\tpk: { name: 'id', type: 'string' },\n\t\t\t\tfields: [{ name: 'authorId', type: 'string' }],\n\t\t\t})\n\t\t\tawait adapter.applyAddForeignKey({\n\t\t\t\tkind: 'addForeignKey',\n\t\t\t\ttable: 'posts',\n\t\t\t\ton: 'authorId',\n\t\t\t\treferences: { table: 'users', column: 'id' },\n\t\t\t\tonDelete: 'cascade',\n\t\t\t})\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\tconst schemas = await a2.introspect()\n\n\t\t\tconst users = schemas.find((s) => s.name === 'users')!\n\t\t\texpect(users.pk).toEqual({ name: 'id', type: 'string' })\n\t\t\texpect(users.fields).toEqual([\n\t\t\t\t{ name: 'email', type: 'string', nullable: false, unique: true },\n\t\t\t\t{ name: 'age', type: 'number', nullable: true },\n\t\t\t])\n\t\t\texpect(users.indexes).toEqual([{ name: 'users_email_idx', on: ['email'], unique: true }])\n\n\t\t\tconst posts = schemas.find((s) => s.name === 'posts')!\n\t\t\texpect(posts.pk).toEqual({ name: 'id', type: 'string' })\n\t\t\texpect(posts.fields).toEqual([{ name: 'authorId', type: 'string', nullable: false }])\n\t\t\texpect(posts.foreignKeys).toEqual([{\n\t\t\t\tname: 'posts_authorId_fk',\n\t\t\t\ton: 'authorId',\n\t\t\t\treferences: { table: 'users', column: 'id' },\n\t\t\t\tonDelete: 'cascade',\n\t\t\t}])\n\n\t\t\tawait a2.disconnect()\n\t\t})\n\n\t\ttest('metadata keys do not leak into data stores', async () => {\n\t\t\tconst adapter = JsonAdapter.create({ filePath })\n\t\t\tawait adapter.connect()\n\t\t\tawait adapter.recordMigration('m-001', 1000)\n\t\t\tawait adapter.applyCreateTable({ kind: 'createTable', name: 'users', pk: { name: 'id', type: 'string' }, fields: [] })\n\n\t\t\texpect(adapter.stores.has('__migrations')).toBe(false)\n\t\t\texpect(adapter.stores.has('__tables')).toBe(false)\n\t\t\tawait adapter.disconnect()\n\n\t\t\tconst a2 = JsonAdapter.create({ filePath })\n\t\t\tawait a2.connect()\n\t\t\texpect(a2.stores.has('__migrations')).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,CACtE,MAAM,KAAK7C,GAAU,oBAAoB6C,CAAM,EAC/C,MAAM,KAAKxB,GAAe,CAC3B,CAEA,MAAM,YAA0C,CAC/C,OAAO,KAAKrB,GAAU,WAAW,CAClC,CACD","names":["open","readFile","rename","unlink","writeFile","v","jsonConnectionPipe","v","JsonAdapter","configurable","OrmAdapter","#inMemory","InMemoryAdapter","#writeQueue","config","#serialize","obj","migrations","tables","name","meta","indexes","foreignKeys","store","records","pk","doc","#atomicWrite","data","tmpPath","writeFile","rename","#persistToDisk","next","raw","readFile","m","fields","fieldName","fspec","schema","result","ops","group","options","filter","create","spec","fn","id","appliedAt","lockPath","deadline","open","err","unlink","change"]}