Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
mdornseif committed Apr 24, 2023
1 parent d5d7b6f commit 443ee29
Show file tree
Hide file tree
Showing 9 changed files with 9,032 additions and 113 deletions.
108 changes: 11 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,17 @@
# DTS User Guide
# datastore-simulator

Congrats! You just saved yourself hours of work by bootstrapping this project with DTS. Let’s get you oriented with what’s here and how to use it.
This is a in process Simulator for the Google Cloud Datastore Node.js Client [@google-cloud/datastore
](https://github.com/googleapis/nodejs-datastore) for easy integration testing.

> This DTS setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use `ts-node-dev`, plain `ts-node`, or simple `tsc`.
It is inspired by [datastore-mock](https://github.com/KoryNunn/datastore-mock) but tries be
Typescript compatible and model the Cloud Datastore API surface as close as possible.

> If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)
datastore-simulator does *not* try to model transactions, queries and consistency.

## Commands

DTS scaffolds your new library inside `/src`.
## See also

To run DTS, use:

```bash
npm start # or yarn start
```

This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.

To do a one-off build, use `npm run build` or `yarn build`.

To run tests, use `npm test` or `yarn test`.

## Configuration

Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.

### Jest

Jest tests are set up to run with `npm test` or `yarn test`.

### Bundle Analysis

[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.

#### Setup Files

This is the folder structure we set up for you:

```txt
/src
index.ts # EDIT THIS
/test
index.test.ts # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
tsconfig.json
```

### Rollup

DTS uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.

### TypeScript

`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.

## Continuous Integration

### GitHub Actions

Two actions are added by default:

- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)

## Optimizations

Please see the main `dts` [optimizations docs](https://github.com/weiran-zsd/dts-cli#optimizations). In particular, know that you can take advantage of development-only optimizations:

```js
// ./types/index.d.ts
declare var __DEV__: boolean;

// inside your code...
if (__DEV__) {
console.log('foo');
}
```

You can also choose to install and use [invariant](https://github.com/weiran-zsd/dts-cli#invariant) and [warning](https://github.com/weiran-zsd/dts-cli#warning) functions.

## Module Formats

CJS, ESModules, and UMD module formats are supported.

The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.

## Named Exports

Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.

## Including Styles

There are many ways to ship styles, including with CSS-in-JS. DTS has no opinion on this, configure how you like.

For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.

## Publishing to NPM

We recommend using [np](https://github.com/sindresorhus/np).
* [datastore-mock](https://www.npmjs.com/package/datastore-mock)
* [@google-cloud/datastore](https://www.npmjs.com/package/@google-cloud/datastore)
* [google-datastore-emulator](https://www.npmjs.com/package/google-datastore-emulator)
* [datastore-api](https://www.npmjs.com/package/datastore-api)
24 changes: 21 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"prepare": "dts build",
"size": "size-limit",
"start": "dts watch",
"test": "dts test"
"test": "yarn vitest test/simulator.spec.ts test/emulator.spec.ts "
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -46,5 +46,23 @@
"path": "dist/datastore-simulator.esm.js",
"limit": "10 KB"
}
]
}
],
"devDependencies": {
"@google-cloud/datastore": "^7.5.1",
"@size-limit/preset-small-lib": "^8.2.4",
"@tsconfig/recommended": "^1.0.2",
"@types/is": "^0.0.21",
"dts-cli": "^2.0.2",
"google-datastore-emulator": "^6.0.1",
"husky": "^8.0.3",
"size-limit": "^8.2.4",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"vitest": "^0.30.1"
},
"dependencies": {
"@google-cloud/promisify": "^3.0.1",
"google-gax": "^3.6.0",
"is": "^3.3.0"
}
}
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('dev only output');
}
return a + b;
};
/*
* index.ts
*
* Created by Dr. Maximillian Dornseif 2023-04-24 in datastore-simulator 0.1.0
* Copyright (c) 2023 Maximillian Dornseif
*/

export {Datastore} from './lib/datastore-simulator'

0 comments on commit 443ee29

Please sign in to comment.