Skip to content

Commit

Permalink
chore!: depend on @comapeo/schema instead of legacy @mapeo/schema (
Browse files Browse the repository at this point in the history
…#19)

Now that `@comapeo/[email protected]` is out, we can depend on that.
  • Loading branch information
EvanHahn authored Sep 17, 2024
1 parent 0991953 commit 3601918
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 107 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mapeo Mock Data

Module and CLI to generate fake data for Mapeo
Module and CLI to generate fake data for CoMapeo

## Installation

Expand Down Expand Up @@ -37,7 +37,7 @@ example output:

#### `generate-mapeo-data`

Generates JSON-formatted Mapeo data based on [`@mapeo/schema`](https://github.com/digidem/mapeo-schema/).
Generates JSON-formatted Mapeo data based on [`@comapeo/schema`](https://github.com/digidem/comapeo-schema/).

- `--schema, -s`: specifies the schema to generate data for. Use the `list-mapeo-schemas` command to learn which ones are available.
- `--version, -v`: (_optional_) specifies the schema version to use for `--schema`. Uses latest version by default.
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { docSchemas } from '@mapeo/schema'
import { docSchemas } from '@comapeo/schema'
import { JSONSchemaFaker, createFakerSchema } from './lib/faker.js'
import { extractSchemaVersion, isValidSchemaName } from './lib/schema.js'

Expand All @@ -14,23 +14,23 @@ export function listSchemas() {
}

/**
* @template {import('@mapeo/schema/dist/types.js').SchemaName} TSchemaName
* @template {import('@comapeo/schema/dist/types.js').SchemaName} TSchemaName
* @param {TSchemaName} schemaName
* @param {{version?: string, count?: number}} [options]
* @returns {Array<Extract<import('@mapeo/schema').MapeoDoc, { schemaName: TSchemaName }>>}
* @returns {Array<Extract<import('@comapeo/schema').MapeoDoc, { schemaName: TSchemaName }>>}
*/
export function generate(schemaName, { count } = {}) {
isValidSchemaName(schemaName)

const targetSchema = docSchemas[schemaName]
const numberToGenerate = count || 1

/** @type {Array<Extract<import('@mapeo/schema').MapeoDoc, { schemaName: TSchemaName }>>} */
/** @type {Array<Extract<import('@comapeo/schema').MapeoDoc, { schemaName: TSchemaName }>>} */
const result = []

for (let i = 0; i < numberToGenerate; i++) {
result.push(
/** @type {Extract<import('@mapeo/schema').MapeoDoc, { schemaName: TSchemaName }>} */ (
/** @type {Extract<import('@comapeo/schema').MapeoDoc, { schemaName: TSchemaName }>} */ (
JSONSchemaFaker.generate(createFakerSchema(targetSchema))
),
)
Expand Down
2 changes: 1 addition & 1 deletion lib/faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { JSONSchemaFaker } from 'json-schema-faker'
import { faker } from '@faker-js/faker'

/**
* @typedef {typeof import('@mapeo/schema').docSchemas[import('@mapeo/schema/dist/types.js').SchemaName]} ValidSchema
* @typedef {typeof import('@comapeo/schema').docSchemas[import('@comapeo/schema/dist/types.js').SchemaName]} ValidSchema
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { docSchemas } from '@mapeo/schema'
import { docSchemas } from '@comapeo/schema'

/**
* @param {string} jsonSchemaId
Expand All @@ -13,7 +13,7 @@ export function extractSchemaVersion(jsonSchemaId) {
*
* @param {string} name
*
* @return {asserts name is import('@mapeo/schema/dist/types.js').SchemaName}
* @return {asserts name is import('@comapeo/schema/dist/types.js').SchemaName}
*/
export function isValidSchemaName(name) {
if (!(name in docSchemas)) {
Expand Down
123 changes: 27 additions & 96 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"typescript": "^5.2.2"
},
"peerDependencies": {
"@mapeo/schema": "^3.0.0-next.28"
"@comapeo/schema": "^1.0.0"
},
"prettier": {
"semi": false,
Expand Down

0 comments on commit 3601918

Please sign in to comment.