Skip to content

Commit

Permalink
commonjs and esm distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
appy-one committed Oct 31, 2022
1 parent 898ff05 commit 07cb6cd
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 10 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# AceBase realtime database

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications. Supports storing of JSON objects, arrays, numbers, strings, booleans, dates and binary (ArrayBuffer) data.
A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications. Supports storing of JSON objects, arrays, numbers, strings, booleans, dates, bigints and binary (ArrayBuffer) data.

Inspired by (and largely compatible with) the Firebase realtime database, with additional functionality and less data sharding/duplication. Capable of storing up to 2^48 (281 trillion) object nodes in a binary database file that can theoretically grow to a max filesize of 8 petabytes.

Expand Down Expand Up @@ -79,11 +79,13 @@ AceBase is easy to set up and runs anywhere: in the cloud, NAS, local server, yo
* [Info](#transaction-logging)
* Multi-process support
* [Info](#multi-process-support)
* [CommonJS and ESM packages](#commonjs-and-esm-packages)
* [Upgrade notices](#upgrade-notices)
* [Known issues](#known-issues)
* [Authors](#authors)
* [Contributing](#contributing)
* [Sponsoring](#sponsoring)

## Getting Started

AceBase is split up into multiple packages:
Expand Down Expand Up @@ -2201,6 +2203,16 @@ AceBase supports running in multiple processes by using interprocess communicati
If you are using pm2 to run your app in a cluster, or run your app in a cloud-based cluster (eg Kubernetes, Docker Swarm), AceBase instances will need some other way to communicate with eachother. This is now possible using an AceBase IPC Server, which allows fast communication using websockets. See [AceBase IPC Server](https://github.com/appy-one/acebase-ipc-server) for more info!
## CommonJS and ESM packages
The TypeScript sources are compiled to both CommonJS and ESM module systems. The sources loaded depend on whether you `import` or `require` acebase:
| Statement | Module system | Target |
|--------------------------------------------|---------------|--------|
| import { AceBase } from 'acebase' | ESM | ES2020 |
| import { AceBase } from 'acebase/commonjs' | CommonJS | ES2017 |
| const { AceBase } = require('acebase') | CommonJS | ES2017 |
See https://github.com/appy-one/acebase/discussions/98 for more info.
## Upgrade notices
* v0.9.68 - To get the used updating context in data event handlers, read from `snap.context()` instead of `snap.ref.context()`. This is to prevent further updates on `snap.ref` to use the same context. If you need to reuse the event context for new updates, you will have to manually set it: `snap.ref.context(snap.context()).update(...)`
Expand Down
47 changes: 47 additions & 0 deletions create-package-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Create CommonJS package.json
cat >dist/cjs/package.json <<JSON
{
"type": "commonjs",
"types": "../types/index.d.ts",
"browser": {
"./index.js": "./browser.js",
"./ipc/index.js": "./ipc/browser.js",
"./promise-fs/index.js": "./promise-fs/browser.js",
"./storage/binary/index.js": "./not-supported.js",
"./storage/mssql/index.js": "./not-supported.js",
"./storage/sqlite/index.js": "./not-supported.js",
"./data-index/index.js": "./not-supported.js",
"./btree/index.js": "./not-supported.js"
}
}
JSON

# Write typings to support Node16 module resolution
cat >dist/cjs/index.d.ts <<TYPESCRIPT
export * from '../types';
TYPESCRIPT

# Create ESM package.json
cat >dist/esm/package.json <<JSON
{
"type": "module",
"types": "../types/index.d.ts",
"browser": {
"./index.js": "./browser.js",
"./ipc/index.js": "./ipc/browser.js",
"./promise-fs/index.js": "./promise-fs/browser.js",
"./storage/binary/index.js": "./not-supported.js",
"./storage/mssql/index.js": "./not-supported.js",
"./storage/sqlite/index.js": "./not-supported.js",
"./data-index/index.js": "./not-supported.js",
"./btree/index.js": "./not-supported.js"
}
}
JSON

# Write typings to support Node16 module resolution
cat >dist/esm/index.d.ts <<TYPESCRIPT
export * from '../types';
TYPESCRIPT
36 changes: 34 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,55 @@
"name": "acebase",
"version": "1.25.2",
"description": "AceBase realtime database. Open source firebase alternative for nodejs and browser, with additional features: indexes, geo, fulltext, queries, custom storage, offline usage, synchronization, live data proxies and more",
"comments": {
"browser": "webpack/browserify file replacements have moved to package.json in dist/cjs and dist/esm. See README.md for more info",
"exports": "See README.md for more info about exported and used ESM and CommonJS distributions"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./esm": {
"import": "./dist/esm/index.js",
"require": "./dist/esm/index.js"
},
"./commonjs": {
"import": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"browser": {
"./dist/cjs/index.js": "./dist/cjs/browser.js",
"./dist/esm/index.js": "./dist/esm/browser.js",
"./dist/cjs/ipc/index.js": "./dist/cjs/ipc/browser.js",
"./dist/esm/ipc/index.js": "./dist/esm/ipc/browser.js",
"./dist/cjs/promise-fs/index.js": "./dist/cjs/promise-fs/browser.js",
"./dist/esm/promise-fs/index.js": "./dist/esm/promise-fs/browser.js",
"./dist/cjs/storage/binary/index.js": "./dist/cjs/not-supported.js",
"./dist/esm/storage/binary/index.js": "./dist/esm/not-supported.js",
"./dist/cjs/storage/mssql/index.js": "./dist/cjs/not-supported.js",
"./dist/esm/storage/mssql/index.js": "./dist/esm/not-supported.js",
"./dist/cjs/storage/sqlite/index.js": "./dist/cjs/not-supported.js",
"./dist/esm/storage/sqlite/index.js": "./dist/esm/not-supported.js",
"./dist/cjs/data-index/index.js": "./dist/cjs/not-supported.js",
"./dist/cjs/btree/index.js": "./dist/cjs/not-supported.js"
"./dist/esm/data-index/index.js": "./dist/esm/not-supported.js",
"./dist/cjs/btree/index.js": "./dist/cjs/not-supported.js",
"./dist/esm/btree/index.js": "./dist/esm/not-supported.js"
},
"types": "./dist/types/index.d.ts",
"private": false,
"repository": "github:appy-one/acebase",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"build": "rm -r ./dist/cjs && rm -r ./dist/types && tsc && npm run browserify",
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:packages && npm run browserify && echo Done!",
"build:clean": "(rm -r ./dist/esm || true) && (rm -r ./dist/cjs || true) && (rm -r ./dist/types || true)",
"build:esm": "tsc -p tsconfig.json && npx tsc-esm-fix ---target='dist/esm'",
"build:cjs": "tsc -p tsconfig-cjs.json",
"build:packages": "bash ./create-package-files",
"browserify": "browserify ./dist/cjs/browser.js -o ./dist/browser.js --standalone acebase --ignore buffer --ignore rxjs && terser ./dist/browser.js -o ./dist/browser.min.js",
"test": "jasmine"
},
Expand Down Expand Up @@ -81,6 +112,7 @@
"eslint-plugin-jasmine": "^4.1.3",
"jasmine": "^3.7.0",
"terser": "^5.15.0",
"tsc-esm-fix": "^2.20.5",
"typescript": "^4.7.4"
},
"funding": [
Expand Down
11 changes: 11 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"outDir": "./dist/cjs",
"declaration": false,
"declarationMap": false,
"declarationDir": null
}
}
15 changes: 8 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["ES2017", "DOM"],
"module": "CommonJS",
"noImplicitAny": true,
"lib": ["esnext","dom"],
"listEmittedFiles": true,
"pretty": true,
"outDir": "./dist/cjs",
"noImplicitAny": true,
"sourceMap": true,
"module": "es2020",
"outDir": "./dist/esm",
"moduleResolution": "node",
"target": "es2020",
"pretty": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./dist/types"
"declarationDir": "./dist/types",
},
"include": ["src/**/*"],
"exclude": [
Expand Down

0 comments on commit 07cb6cd

Please sign in to comment.