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

feat!: rename to @comapeo/schema #260

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Build steps

1. `npm run generate` will generate type definitions and encode/decode functions from `.proto` files, and generate type definitions from json schema files, and place them in `generated`. It will also generate validation functions from json schema files and place that in `dist`.
1. `npm run build:generate` will generate type definitions and encode/decode functions from `.proto` files, and generate type definitions from json schema files, and place them in `generated`. It will also generate validation functions from json schema files and place that in `dist`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly related, but this was incorrect.

2. `rootDirs` is set in `tsconfig.json` so that files in `src` can import from `generated` as if the two folders were merged
3. `tsc` generates `.js` and `.d.ts` from the files in `src` and `generated` and outputs to `intermediate`
4. A final copy step is needed to merge `intermediate/generated` and `intermediate/src` into `dist`.
Expand All @@ -13,7 +13,7 @@ Please publish to npm via Github using the release workflow, rather than publish

### 1. Prepare a release

- Navigate to the [release action workflow](https://github.com/digidem/mapeo-schema/actions/workflows/release.yml) and click the "Run workflow" dropdown.
- Navigate to the [release action workflow](https://github.com/digidem/comapeo-schema/actions/workflows/release.yml) and click the "Run workflow" dropdown.
- Select the semver release, e.g. "patch" for bug fixes, "minor" for new features, and "major" for breaking changes. For pre-release see below
- Click "Run workflow" button.

Expand All @@ -30,13 +30,13 @@ This will open a new Pull Request with a draft release

Prereleases are useful for testing new versions of this package without affecting existing dependent packages. Ideally work on a pre-release should be on a separate branch, e.g. create a `next` branch from `master`.

To prepare the release, select "Run workflow" on the [release action workflow](https://github.com/digidem/mapeo-schema/actions/workflows/release.yml) as above, but select the branch `next` (or whatever branch you are using for prerelease development) for "Use workflow from", and for the "`semver` to use" option, select:
To prepare the release, select "Run workflow" on the [release action workflow](https://github.com/digidem/comapeo-schema/actions/workflows/release.yml) as above, but select the branch `next` (or whatever branch you are using for prerelease development) for "Use workflow from", and for the "`semver` to use" option, select:

- `prepatch` to create a new patch prerelease, e.g. if the current version is `v3.0.0`, then this will generate a new release `v3.0.1-next.0`.
- `preminor` to create a new minor prerelease, e.g. if the current version is `v3.0.0` then this will generate a new release `v3.1.0-next.0`.
- `premajor` to create a new major prerelease, e.g. if the current version is `v3.0.0` then this will generate a new release `v4.0.0-next.0`.
- `prelease` to bump the prerelease version if the current version on the branch that you target is already a prerelease and you want to create a new prerelease, e.g. if the current version on the target branch is `v3.0.1-next.0` then this will generate a new release `v3.0.1-next.1`.

The pre-releases will be published to npm with the `next` [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages). Publishing a pre-release will not change the `latest` tag, so that normal installs of `npm install @mapeo/schema` will not get the pre-release. To install the pre-release for testing, use `npm install @mapeo/schema@latest`.
The pre-releases will be published to npm with the `next` [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages). Publishing a pre-release will not change the `latest` tag, so that normal installs of `npm install @comapeo/schema` will not get the pre-release. To install the pre-release for testing, use `npm install @comapeo/schema@latest`.

To publish a `latest` release from a pre-release, first merge the pre-release branch to master, then follow the usual "Prepare a release" steps from above, but select `auto` for the "`semver` to use" option. If you have a prerelease version `v3.0.1-next.3` then this will publish a release called `v3.0.1`.
62 changes: 15 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# mapeo-schema
# @comapeo/schema

[![Build Status](https://img.shields.io/travis/digidem/mapeo-schema.svg)](https://travis-ci.org/digidem/mapeo-schema)
[![npm](https://img.shields.io/npm/v/mapeo-schema.svg)](https://www.npmjs.com/package/mapeo-schema)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these badges. We don't use Travis CI or Standard style, and I didn't feel like updating the npm badge for a version that doesn't (yet) exist.

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?maxAge=2592000)](http://standardjs.com/)

> Document schemas, validators and flow types for Mapeo
JSON Schema and TypeScript types for CoMapeo.

Original draft: https://hackmd.io/wlMcMM65TmuPXGYOEbOR2g#

Expand All @@ -14,37 +10,37 @@ Original draft: https://hackmd.io/wlMcMM65TmuPXGYOEbOR2g#
- [Usage](#usage)
- [API](#api)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)

## Install

```sh
npm install --save mapeo-schema
npm install --save @comapeo/schema
```

## Usage

### JS validation functions

```js
const mapeoSchema = require('mapeo-schema')
// also
const validateObservation = require('mapeo-schema/validateObservation')
import { validate } from '@comapeo/schema'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated these code examples.

const testObservation = {...}
const testObservation = {
/* ... */
}

const isValid = mapeoSchema.validateObservation(testObservation);
const isValid = validate('observation', testObservation)
// returns true if validates against schema, false otherwise.
// errors a static prop on mapeoSchema.validateObservation.errors
```

### Flow types
### TypeScript types

```js
import type { Observation } from 'mapeo-schema'
```typescript
import type { Observation } from '@comapeo/schema'

const myObs: Observation = {...}
const myObs: Observation = {
/* ... */
}
```

## API
Expand All @@ -53,34 +49,6 @@ const myObs: Observation = {...}

[@digidem](https://github.com/digidem)

## Contributing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this whole section because I think it's outdated.

**It looks like there is no code in this repo**. All the code is generated from
the [JSON Schema definitions](schema/). To build the validator functions and
flow definitions:

```sh
npm run build
```

Tests are also generated dynamically. Place an example minimal and valid JSON
for a particular schema in the [examples](examples/) folder, with a filename
that matches the schema filename, e.g. if you add a schema called
`mySchema.json` then add an example `mySchema.minimal.json` and
`mySchema.full.json`. "Minimal" means with only the required properties, where
"full" means with all the defined properties in the schema document. To run
tests:

```sh
npm test
```

Before publishing, update the docs with:

```sh
npm run docs
```

## License

MIT © 2019 Digital Democracy
MIT © 2024 Awana Digital
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mapeo/schema",
"version": "3.0.0-next.27",
"description": "JSON schema and flow types for Mapeo",
"name": "@comapeo/schema",
"version": "0.0.0",
"description": "JSON Schema and TypeScript types for CoMapeo",
"main": "dist/index.js",
"type": "module",
"scripts": {
Expand All @@ -25,18 +25,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/digidem/mapeo-schema.git"
"url": "git+https://github.com/digidem/comapeo-schema.git"
},
"keywords": [
"mapeo",
"schema"
],
"author": "Digital Democracy",
"author": "Awana Digital",
"license": "MIT",
"bugs": {
"url": "https://github.com/digidem/mapeo-schema/issues"
"url": "https://github.com/digidem/comapeo-schema/issues"
},
"homepage": "https://github.com/digidem/mapeo-schema#readme",
"homepage": "https://github.com/digidem/comapeo-schema#readme",
"devDependencies": {
"@bufbuild/buf": "^1.26.1",
"@json-schema-tools/dereferencer": "^1.6.3",
Expand Down
5 changes: 0 additions & 5 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export function parseVersionId(versionId: string): VersionIdObject {
return { coreDiscoveryKey, index }
}

/**
* @template {import('@mapeo/schema').MapeoDoc & { forks?: string[] }} T
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This referred to @mapeo/schema, but it didn't actually do anything because this is a TypeScript file. Rather than update the reference, I just removed all of it.

* @param {T} doc
* @returns {Omit<T, 'docId' | 'versionId' | 'originalVersionId' | 'links' | 'forks' | 'createdAt' | 'updatedAt' | 'deleted'>}
*/
export function valueOf<TDoc extends MapeoDoc>(
doc: TDoc & { forks?: string[] }
): FilterBySchemaName<MapeoValue, TDoc['schemaName']> {
Expand Down
Loading