Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to bun & update deps #185

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 0 additions & 11 deletions .eslintrc.js

This file was deleted.

14 changes: 5 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ jobs:
steps:
- uses: actions/checkout@v3

# Install node and yarn
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- run: yarn --prefer-offline
- name: Install bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install --frozen-lockfile

# Run verifications
- run: yarn test
- run: yarn lint --max-warnings 0
- run: yarn build
- run: yarn size
- run: yarn docs:ci
- run: yarn test
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2022 Hein Rutjes
Copyright (c) 2017-2024 Hein Rutjes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/License.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2017-2022 Hein Rutjes
Copyright (c) 2017-2024 Hein Rutjes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
32 changes: 16 additions & 16 deletions examples/todoApp/src/store.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import * as firebase from "firebase/app";
import "firebase/firestore";
import { initFirestorter, Collection, Document } from "firestorter";
import { struct } from "superstruct";
import * as firebase from 'firebase/app';
import 'firebase/firestore';
import { initFirestorter, Collection, Document } from 'firestorter';
import { struct } from 'superstruct';

firebase.initializeApp({
apiKey: "AIzaSyBiY-6xQrji8oe5E90d1P8J8OvfIo3F6kE",
authDomain: "firestore-mobx-todo.firebaseapp.com",
databaseURL: "https://firestore-mobx-todo.firebaseio.com",
projectId: "firestore-mobx-todo",
storageBucket: "firestore-mobx-todo.appspot.com",
messagingSenderId: "680642766706"
apiKey: 'AIzaSyBiY-6xQrji8oe5E90d1P8J8OvfIo3F6kE',
authDomain: 'firestore-mobx-todo.firebaseapp.com',
databaseURL: 'https://firestore-mobx-todo.firebaseio.com',
projectId: 'firestore-mobx-todo',
storageBucket: 'firestore-mobx-todo.appspot.com',
messagingSenderId: '680642766706',
});

initFirestorter({ firebase: firebase });

class Todo extends Document {
constructor(source, options) {
super(source, {
...(options || {}),
...options,
schema: struct({
text: "string",
finished: "boolean?"
})
text: 'string',
finished: 'boolean?',
}),
});
}
}

const todos = new Collection("todos", {
createDocument: (source, options) => new Todo(source, options)
const todos = new Collection('todos', {
createDocument: (source, options) => new Todo(source, options),
});

export { todos };
7 changes: 7 additions & 0 deletions jest.config.compat.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
//preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm', // or other ESM presets
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/initCompat.ts'],
};
3 changes: 0 additions & 3 deletions jest.config.compat.js

This file was deleted.

6 changes: 6 additions & 0 deletions jest.config.web.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/initWeb.ts'],
};
3 changes: 0 additions & 3 deletions jest.config.web.js

This file was deleted.

69 changes: 33 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
"mobx-firestore",
"firestore-collection"
],
"main": "dist/index.js",
"module": "dist/firestorter.esm.js",
"typings": "dist/index.d.ts",
"type": "module",
"exports": {
".": "./dist/index.js"
},
"types": "dist/index.d.ts",
"engines": {
"node": ">=14.17"
},
"sideEffects": false,
"repository": "https://github.com/IjzerenHein/firestorter",
"author": "IjzerenHein <hrutjes@gmail.com>",
Expand All @@ -27,16 +32,16 @@
"web"
],
"scripts": {
"build": "yarn build:dist && yarn build:web",
"build:dist": "tsdx build",
"build": "bun build:dist && bun build:web",
"build:dist": "tsc",
"build:web": "cp src/IContext.ts web && tsc web/index.ts --declaration",
"lint": "tsdx lint src test",
"prepare": "yarn build",
"size": "size-limit",
"test": "yarn test:web && yarn test:compat",
"test:web": "node ./test/seedSampleData.js && cp src/IContext.ts web && tsdx test --config jest.config.web.js",
"test:compat": "node ./test/seedSampleData.js && tsdx test --config jest.config.compat.js",
"cov": "jest --coverage",
"lint": "oxlint",
"test": "bun test:web && bun test:compat",
"test:web": "bun run test:seed && cp src/IContext.ts web && bun run jest --config jest.config.web.cjs",
"test:web2": "bun run test:seed && cp src/IContext.ts web && test --config ./test/initWeb.ts",
"test:compat": "bun run test:seed && bun test --preload jest.config.compat.js",
"test:seed": "bun --bun ./test/seedSampleData.ts",
"cov": "bun test --coverage",
"docs:document": "jsdoc2md --files 'src/Document.ts' --configure jsdoc2md.json > ./docs/api/Document.md",
"docs:collection": "jsdoc2md --files 'src/Collection.ts' --configure jsdoc2md.json > ./docs/api/Collection.md",
"docs:aggregatecollection": "jsdoc2md --files 'src/AggregateCollection.ts' --configure jsdoc2md.json > ./docs/api/AggregateCollection.md",
Expand All @@ -45,42 +50,34 @@
"docs:initfunctions": "jsdoc2md --files 'src/init.ts' 'src/compat.ts' 'web/index.ts' --configure jsdoc2md.json > ./docs/api/InitFunctions.md",
"docs:utilityfunctions": "jsdoc2md --files 'src/Utils.ts' --configure jsdoc2md.json > ./docs/api/UtilityFunctions.md",
"docs:geofunctions": "jsdoc2md --files 'src/GeoHash.ts' --configure jsdoc2md.json > ./docs/api/GeoFunctions.md",
"docs:build": "yarn docs:document && yarn docs:collection && yarn docs:aggregatecollection && yarn docs:geoquery && yarn docs:types && yarn docs:initfunctions && yarn docs:geofunctions && yarn docs:utilityfunctions",
"docs:serve": "docsify serve docs",
"docs:ci": "yarn docs:build && node ./scripts/checkUncommittedDocChanges.js"
"docs:build": "bun docs:document && bun docs:collection && bun docs:aggregatecollection && bun docs:geoquery && bun docs:types && bun docs:initfunctions && bun docs:geofunctions && bun docs:utilityfunctions",
"docs:ci": "bun docs:build && bun --bun ./scripts/checkUncommittedDocChanges.ts"
},
"size-limit": [
{
"path": "dist/firestorter.cjs.production.min.js",
"limit": "15 KB"
},
{
"path": "dist/firestorter.esm.js",
"limit": "15 KB"
}
],
"dependencies": {
"@babel/preset-typescript": "^7.18.6",
"@babel/preset-typescript": "^7.23.3",
"lodash.isequal": "^4.5.0"
},
"peerDependencies": {
"mobx": ">= 6"
},
"devDependencies": {
"@expo/spawn-async": "^1.7.0",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@expo/spawn-async": "^1.7.2",
"@release-notes/cli": "^0.3.0",
"@size-limit/preset-small-lib": "^8.1.0",
"@types/lodash.isequal": "^4.5.6",
"codecov": "^3.8.3",
"firebase": "^9.15.0",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/bun": "^1.0.0",
"@types/jest": "^29.5.11",
"@types/lodash.isequal": "^4.5.8",
"firebase": "^10.7.1",
"jest": "^29.7.0",
"jsdoc-babel": "^0.5.0",
"jsdoc-to-markdown": "^8.0.0",
"mobx": "^6.7.0",
"size-limit": "^8.1.0",
"mobx": "^6.12.0",
"oxlint": "^0.0.22",
"superstruct": "^0.8.2",
"tsdx": "^0.14.1",
"tslib": "^2.4.1",
"typescript": "^4.9.4"
"ts-jest": "^29.1.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
},
"resolutions": {
"prettier": "^2.8.1"
Expand Down
22 changes: 0 additions & 22 deletions scripts/checkUncommittedDocChanges.js

This file was deleted.

22 changes: 22 additions & 0 deletions scripts/checkUncommittedDocChanges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import spawnAsync from '@expo/spawn-async';

async function checkUncommittedDocChanges() {
const child = await spawnAsync('git', ['status', '--porcelain', '../docs'], {
stdio: 'pipe',
cwd: __dirname,
});

const lines = child.stdout?.trim().split(/\r\n?|\n/g) ?? [];
if (lines.length > 0) {
console.error(`The following doc files need to be rebuilt and committed:`);
lines.map(function (line) {
console.warn(line.replace(/^\s*\S+\s*/g, ''));
});

throw new Error(
`The docs folder for has uncommitted changes. Run 'bun docs:build' and commit the docs changes.`
);
}
}

checkUncommittedDocChanges();
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
yarn codecov
yarn release-notes publish --scope IjzerenHein --name Firestorter --token $1 ./CHANGELOG.md
bun codecov
bun release-notes publish --scope IjzerenHein --name Firestorter --token $1 ./CHANGELOG.md
14 changes: 8 additions & 6 deletions src/AggregateCollection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { CollectionReference, Query } from 'firebase/firestore';
import { runInAction, autorun, computed, makeObservable, IObservableArray } from 'mobx';

import Collection from './Collection';
import Document from './Document';
import Collection from './Collection.js';
import Document from './Document.js';
import {
ICollection,
DocumentSource,
Expand All @@ -12,9 +12,9 @@ import {
IEnhancedObservableDelegate,
IContext,
IHasContext,
} from './Types';
import { isEqual } from './Utils';
import { enhancedObservable } from './enhancedObservable';
} from './Types.js';
import { isEqual } from './Utils.js';
import { enhancedObservable } from './enhancedObservable.js';

export type AggregateCollectionOrderBy<T> = (a: T, b: T) => number;
export type AggregateCollectionFilterBy<T> = (doc: T) => boolean;
Expand Down Expand Up @@ -310,7 +310,9 @@ class AggregateCollection<
this.collectionRecycleMap = {};
cols.forEach((col, index) => {
const query = queries[index];
this.collectionRecycleMap[query.key] = col;
if (query !== undefined) {
this.collectionRecycleMap[query.key] = col;
}
});

// Update the queries
Expand Down
10 changes: 5 additions & 5 deletions src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from 'firebase/firestore';
import { IObservableArray, IObservableValue, observable, reaction, runInAction } from 'mobx';

import Document from './Document';
import Document from './Document.js';
import {
CollectionQuery,
CollectionSource,
Expand All @@ -20,10 +20,10 @@ import {
Mode,
IContext,
IHasContext,
} from './Types';
import { verifyMode } from './Utils';
import { enhancedObservable } from './enhancedObservable';
import { getContext } from './init';
} from './Types.js';
import { verifyMode } from './Utils.js';
import { enhancedObservable } from './enhancedObservable.js';
import { getContext } from './init.js';

// * @param {Number} [options.limit] Maximum number of documents to fetch (see `Collection.limit`)

Expand Down
8 changes: 4 additions & 4 deletions src/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
Mode,
IContext,
IHasContext,
} from './Types';
import { mergeUpdateData, verifyMode, isEqual } from './Utils';
import { enhancedObservable } from './enhancedObservable';
import { getContext } from './init';
} from './Types.js';
import { mergeUpdateData, verifyMode, isEqual } from './Utils.js';
import { enhancedObservable } from './enhancedObservable.js';
import { getContext } from './init.js';

/**
* @private
Expand Down
6 changes: 3 additions & 3 deletions src/GeoHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function fromGeoPoint(point: IGeoPoint): number[] {

function toGeoPoint(location: number[]): IGeoPoint {
return {
latitude: location[0],
longitude: location[1],
latitude: location[0]!,
longitude: location[1]!,
};
}

Expand Down Expand Up @@ -578,7 +578,7 @@ export function flattenGeohashRange(geohash1: string, geohash2: string): string[
*/
export function flattenGeohashes(geohashes: string[][]): string[] {
const set = new Set<string>();
geohashes.forEach((a) => flattenGeohashRange(a[0], a[1]).forEach((geohash) => set.add(geohash)));
geohashes.forEach((a) => flattenGeohashRange(a[0]!, a[1]!).forEach((geohash) => set.add(geohash)));
return Array.from(set);
}

Expand Down
8 changes: 4 additions & 4 deletions src/GeoQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import AggregateCollection, {
IAggregateCollectionOptions,
IAggregateCollectionQuery,
AggregateCollectionQueriesFn,
} from './AggregateCollection';
import { IGeoRegion, getGeohashesForRegion } from './GeoHash';
import { CollectionSource, ICollectionDocument } from './Types';
import { getContext } from './init';
} from './AggregateCollection.js';
import { IGeoRegion, getGeohashesForRegion } from './GeoHash.js';
import { CollectionSource, ICollectionDocument } from './Types.js';
import { getContext } from './init.js';

export type GeoQueryRegion = IGeoRegion | (() => IGeoRegion | void);
export type GeoQueryHash = string[];
Expand Down
2 changes: 1 addition & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
CollectionReference,
Query,
} from 'firebase/firestore';
import type { IContext } from './IContext';
import type { IContext } from './IContext.js';

export { IContext };

Expand Down
Loading
Loading