Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/kind-apricots-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/drizzle-driver': minor
'@powersync/kysely-driver': minor
'@powersync/attachments': minor
---

Updated package exports to reflect ESM exports. Added CommonJS exports.
5 changes: 5 additions & 0 deletions .changeset/unlucky-singers-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/react': minor
---

Update package exports to reflect ESM exports.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/tsconfig.tsbuildinfo
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"format": "prettier --write .",
"lint": "eslint .",
"release": "pnpm build:packages:prod && pnpm changeset publish",
"test": "pnpm run -r --workspace-concurrency=0 test"
"test": "pnpm run -r --workspace-concurrency=1 test --run"
},
"keywords": [],
"type": "module",
Expand All @@ -33,13 +33,17 @@
"@actions/core": "^1.10.1",
"@changesets/cli": "2.27.2",
"@pnpm/workspace.find-packages": "^4.0.2",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "^12.1.4",
"@vitest/browser": "^3.2.4",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"playwright": "^1.51.0",
"prettier": "^3.2.5",
"prettier-plugin-embed": "^0.4.15",
"prettier-plugin-sql": "^0.18.1",
"rollup": "4.14.3",
"typescript": "^5.7.2",
"vitest": "^3.2.4"
}
Expand Down
21 changes: 16 additions & 5 deletions packages/attachments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@
"url": "https://github.com/powersync-ja/powersync-js/issues"
},
"description": "An PowerSync library to manage attachments for TypeScript and React Native apps",
"main": "./lib/index.js",
"type": "module",
"main": "./dist/index.cjs",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./dist/index.cjs",
"default": "./lib/index.js"
}
},
"files": [
"lib"
"lib",
"dist"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b --sourceMap false",
"clean": "rm -rf lib tsconfig.tsbuildinfo node_modules",
"build": "tsc -b && rollup --config",
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
"clean": "rm -rf lib",
"watch": "tsc -b -w",
"test": "pnpm build && vitest"
},
Expand Down
31 changes: 31 additions & 0 deletions packages/attachments/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';

/** @type {import('rollup').RollupOptions} */
export default (commandLineArgs) => {
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';

// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
delete commandLineArgs.sourceMap;

return {
input: 'src/index.ts',
output: {
format: 'cjs',
file: 'dist/index.cjs',
sourcemap: sourceMap,
exports: 'named'
},
plugins: [
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
outDir: 'dist',
sourceMap
})
],
external: ['@powersync/common']
};
};
4 changes: 2 additions & 2 deletions packages/attachments/src/AbstractAttachmentQueue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractPowerSyncDatabase, Transaction } from '@powersync/common';
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema';
import { EncodingType, StorageAdapter } from './StorageAdapter';
import { ATTACHMENT_TABLE, AttachmentRecord, AttachmentState } from './Schema.js';
import { EncodingType, StorageAdapter } from './StorageAdapter.js';

export interface AttachmentQueueOptions {
powersync: AbstractPowerSyncDatabase;
Expand Down
6 changes: 3 additions & 3 deletions packages/attachments/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './Schema';
export * from './StorageAdapter';
export * from './Schema.js';
export * from './StorageAdapter.js';

export * from './AbstractAttachmentQueue';
export * from './AbstractAttachmentQueue.js';
32 changes: 15 additions & 17 deletions packages/attachments/tests/attachments/AttachmentQueue.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import * as commonSdk from '@powersync/common';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AbstractAttachmentQueue } from '../../src/AbstractAttachmentQueue';
import { AttachmentRecord, AttachmentState } from '../../src/Schema';
import { AbstractPowerSyncDatabase } from '@powersync/common';
import { StorageAdapter } from '../../src/StorageAdapter';
import { AbstractAttachmentQueue } from '../../src/AbstractAttachmentQueue.js';
import { AttachmentRecord, AttachmentState } from '../../src/Schema.js';
import { StorageAdapter } from '../../src/StorageAdapter.js';

const record = {
id: 'test-1',
filename: 'test.jpg',
state: AttachmentState.QUEUED_DOWNLOAD
}
};

const mockPowerSync = {
currentStatus: { status: 'initial' },
registerListener: vi.fn(() => {}),
resolveTables: vi.fn(() => ['table1', 'table2']),
onChangeWithCallback: vi.fn(),
getAll: vi.fn(() => Promise.resolve([{id: 'test-1'}, {id: 'test-2'}])),
getAll: vi.fn(() => Promise.resolve([{ id: 'test-1' }, { id: 'test-2' }])),
execute: vi.fn(() => Promise.resolve()),
getOptional: vi.fn((_query, params) => Promise.resolve(record)),
watch: vi.fn((query, params, callbacks) => {
callbacks?.onResult?.({ rows: { _array: [{id: 'test-1'}, {id: 'test-2'}] } });
callbacks?.onResult?.({ rows: { _array: [{ id: 'test-1' }, { id: 'test-2' }] } });
}),
writeTransaction: vi.fn(async (callback) => {
await callback({
Expand Down Expand Up @@ -57,9 +55,9 @@ describe('attachments', () => {

it('should not download attachments when downloadRecord is called with downloadAttachments false', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: false
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: false
});

await queue.downloadRecord(record);
Expand All @@ -69,9 +67,9 @@ describe('attachments', () => {

it('should download attachments when downloadRecord is called with downloadAttachments true', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
});

await queue.downloadRecord(record);
Expand All @@ -82,9 +80,9 @@ describe('attachments', () => {
// Testing the inverse of this test, i.e. when downloadAttachments is false, is not required as you can't wait for something that does not happen
it('should not download attachments with watchDownloads is called with downloadAttachments false', async () => {
const queue = new TestAttachmentQueue({
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
powersync: mockPowerSync as any,
storage: mockStorage,
downloadAttachments: true
});

queue.watchDownloads();
Expand Down
7 changes: 5 additions & 2 deletions packages/attachments/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"extends": "../../tsconfig.base",
"compilerOptions": {
"baseUrl": "./",
"jsx": "react",
"rootDir": "src",
"outDir": "./lib"
"module": "node16",
"moduleResolution": "node16",
"target": "es6",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo"
},
"references": [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"types": "lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./dist/bundle.mjs",
"require": "./dist/bundle.cjs",
"types": "./lib/index.d.ts",
"default": "./dist/bundle.mjs"
}
},
Expand All @@ -35,7 +35,7 @@
"scripts": {
"build": "tsc -b && rollup -c rollup.config.mjs",
"build:prod": "tsc -b --sourceMap false && rollup -c rollup.config.mjs --sourceMap false",
"clean": "rm -rf lib dist tsconfig.tsbuildinfo node_modules",
"clean": "rm -rf lib dist",
"test": "vitest"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"preserveConstEnums": true,
"esModuleInterop": false,
"skipLibCheck": false,
"strictNullChecks": true
"strictNullChecks": true,
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo"
},
"include": ["src/**/*"]
}
21 changes: 16 additions & 5 deletions packages/drizzle-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
"name": "@powersync/drizzle-driver",
"version": "0.4.0",
"description": "Drizzle driver for PowerSync",
"main": "lib/src/index.js",
"type": "module",
"main": "dist/index.cjs",
"module": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"exports": {
".": {
"types": "./lib/src/index.d.ts",
"import": "./lib/src/index.js",
"require": "./dist/index.cjs",
"default": "./lib/src/index.js"
}
},
"author": "JOURNEYAPPS",
"license": "Apache-2.0",
"files": [
"lib"
"lib",
"dist"
],
"repository": "https://github.com/powersync-ja/powersync-js",
"bugs": {
Expand All @@ -19,9 +30,9 @@
},
"homepage": "https://docs.powersync.com",
"scripts": {
"build": "tsc --build",
"build:prod": "tsc --build --sourceMap false",
"clean": "rm -rf lib tsconfig.tsbuildinfo",
"build": "tsc -b && rollup --config",
"build:prod": "tsc -b --sourceMap false && rollup --config --sourceMap=false",
"clean": "rm -rf lib",
"watch": "tsc --build -w",
"test": "vitest"
},
Expand Down
36 changes: 36 additions & 0 deletions packages/drizzle-driver/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';

/** @type {import('rollup').RollupOptions} */
export default (commandLineArgs) => {
const sourceMap = (commandLineArgs.sourceMap || 'true') == 'true';

// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
delete commandLineArgs.sourceMap;

return {
input: 'src/index.ts',
output: {
format: 'cjs',
file: 'dist/index.cjs',
sourcemap: sourceMap,
exports: 'named'
},
plugins: [
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
outDir: 'dist',
sourceMap,
/**
* The Typescript plugin complains about internal Drizzle types not matching when selecting
* other moduleResolution settings.
*/
moduleResolution: 'bundler'
})
],
external: ['@powersync/common', /^drizzle-orm(\/.*)?$/]
};
};
8 changes: 4 additions & 4 deletions packages/drizzle-driver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
wrapPowerSyncWithDrizzle,
type DrizzleQuery,
type PowerSyncSQLiteDatabase
} from './sqlite/PowerSyncSQLiteDatabase';
import { toCompilableQuery } from './utils/compilableQuery';
} from './sqlite/PowerSyncSQLiteDatabase.js';
import { toCompilableQuery } from './utils/compilableQuery.js';
import {
DrizzleAppSchema,
toPowerSyncTable,
Expand All @@ -14,14 +14,14 @@ import {
type ExtractPowerSyncColumns,
type TableName,
type TablesFromSchemaEntries
} from './utils/schema';
} from './utils/schema.js';

export {
DrizzleAppSchema,
DrizzleAppSchemaOptions,
DrizzleQuery,
DrizzleTablePowerSyncOptions,
DrizzleTableWithPowerSyncOptions,
DrizzleQuery,
Expand,
ExtractPowerSyncColumns,
PowerSyncSQLiteDatabase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SQLiteTransaction,
type SQLiteTransactionConfig
} from 'drizzle-orm/sqlite-core/session';
import { PowerSyncSQLitePreparedQuery } from './PowerSyncSQLitePreparedQuery';
import { PowerSyncSQLitePreparedQuery } from './PowerSyncSQLitePreparedQuery.js';

export interface PowerSyncSQLiteSessionOptions {
logger?: Logger;
Expand Down
6 changes: 3 additions & 3 deletions packages/drizzle-driver/src/sqlite/PowerSyncSQLiteDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { SQLiteTransaction } from 'drizzle-orm/sqlite-core';
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core/db';
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core/dialect';
import type { DrizzleConfig } from 'drizzle-orm/utils';
import { toCompilableQuery } from './../utils/compilableQuery';
import { PowerSyncSQLiteSession } from './PowerSyncSQLiteSession';
import { PowerSyncSQLiteTransactionConfig } from './PowerSyncSQLiteBaseSession';
import { toCompilableQuery } from './../utils/compilableQuery.js';
import { PowerSyncSQLiteTransactionConfig } from './PowerSyncSQLiteBaseSession.js';
import { PowerSyncSQLiteSession } from './PowerSyncSQLiteSession.js';

export type DrizzleQuery<T> = { toSQL(): Query; execute(): Promise<T | T[]> };

Expand Down
13 changes: 3 additions & 10 deletions packages/drizzle-driver/src/sqlite/PowerSyncSQLiteSession.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { AbstractPowerSyncDatabase, DBAdapter } from '@powersync/common';
import { entityKind } from 'drizzle-orm/entity';
import type { RelationalSchemaConfig, TablesRelationalConfig } from 'drizzle-orm/relations';
import { type Query } from 'drizzle-orm/sql/sql';
import type { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core/dialect';
import type { SelectedFieldsOrdered } from 'drizzle-orm/sqlite-core/query-builders/select.types';
import {
type PreparedQueryConfig as PreparedQueryConfigBase,
type SQLiteExecuteMethod
} from 'drizzle-orm/sqlite-core/session';
import { PowerSyncSQLitePreparedQuery } from './PowerSyncSQLitePreparedQuery';
import {
PowerSyncSQLiteBaseSession,
PowerSyncSQLiteSessionOptions,
PowerSyncSQLiteTransaction,
PowerSyncSQLiteTransactionConfig,
PowerSyncSQLiteBaseSession
} from './PowerSyncSQLiteBaseSession';
PowerSyncSQLiteTransactionConfig
} from './PowerSyncSQLiteBaseSession.js';

export class PowerSyncSQLiteSession<
TFullSchema extends Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle-driver/tests/setup/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractPowerSyncDatabase, column, PowerSyncDatabase, Schema, Table } from '@powersync/web';
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { wrapPowerSyncWithDrizzle } from '../../src/sqlite/PowerSyncSQLiteDatabase';
import { wrapPowerSyncWithDrizzle } from '../../src/sqlite/PowerSyncSQLiteDatabase.js';

const users = new Table({
name: column.text
Expand Down
Loading