ipld-schema-describer 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'daily'
7
+ commit-message:
8
+ prefix: 'chore'
9
+ include: 'scope'
10
+ - package-ecosystem: 'npm'
11
+ directory: '/'
12
+ schedule:
13
+ interval: 'daily'
14
+ commit-message:
15
+ prefix: 'chore'
16
+ include: 'scope'
17
+ - package-ecosystem: 'npm'
18
+ directory: '/examples/'
19
+ schedule:
20
+ interval: 'daily'
21
+ ignore:
22
+ - dependency-name: "@ipld/car"
23
+ commit-message:
24
+ prefix: 'chore'
25
+ include: 'scope'
@@ -0,0 +1,60 @@
1
+ name: Test & Maybe Release
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ node: [14.x, 16.x, lts/*]
9
+ os: [macos-latest, ubuntu-latest, windows-latest]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - name: Checkout Repository
13
+ uses: actions/checkout@v3
14
+ - name: Use Node.js ${{ matrix.node }}
15
+ uses: actions/setup-node@v3.4.1
16
+ with:
17
+ node-version: ${{ matrix.node }}
18
+ - name: Install Dependencies
19
+ run: |
20
+ npm install --no-progress --no-package-lock
21
+ - name: Run tests
22
+ run: |
23
+ npm test
24
+ release:
25
+ name: Release
26
+ needs: test
27
+ runs-on: ubuntu-latest
28
+ if: github.event_name == 'push' && github.ref == 'refs/heads/master'
29
+ steps:
30
+ - name: Checkout
31
+ uses: actions/checkout@v3
32
+ with:
33
+ fetch-depth: 0
34
+ - name: Setup Node.js
35
+ uses: actions/setup-node@v3.4.1
36
+ with:
37
+ node-version: 16
38
+ - name: Install dependencies
39
+ run: |
40
+ npm install --no-progress --no-package-lock --no-save
41
+ - name: Build
42
+ run: |
43
+ npm run build
44
+ - name: Install plugins
45
+ run: |
46
+ npm install \
47
+ @semantic-release/commit-analyzer \
48
+ conventional-changelog-conventionalcommits \
49
+ @semantic-release/release-notes-generator \
50
+ @semantic-release/npm \
51
+ @semantic-release/github \
52
+ @semantic-release/git \
53
+ @semantic-release/changelog \
54
+ --no-progress --no-package-lock --no-save
55
+ - name: Release
56
+ env:
57
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
59
+ run: npx semantic-release
60
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,127 @@
1
+ ## [2.0.0](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.10...v2.0.0) (2022-08-16)
2
+
3
+
4
+ ### ⚠ BREAKING CHANGES
5
+
6
+ * publish as ESM-only
7
+ * update dependencies, upgrade schema DMT & library usage
8
+
9
+ ### Features
10
+
11
+ * publish as ESM-only ([ea4a423](https://github.com/rvagg/js-ipld-schema-describer/commit/ea4a4235a8f0373d8403a4b5a54c74327ffdf1e9))
12
+ * update dependencies, upgrade schema DMT & library usage ([c236af1](https://github.com/rvagg/js-ipld-schema-describer/commit/c236af1793f627f30a89d69c9eaf29f0cab82f2c))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * update action ([418ce94](https://github.com/rvagg/js-ipld-schema-describer/commit/418ce945da4b49cc5270a790760d44f2f7bee767))
18
+
19
+
20
+ ### Trivial Changes
21
+
22
+ * **no-release:** bump actions/setup-node from 3.1.1 to 3.2.0 ([#24](https://github.com/rvagg/js-ipld-schema-describer/issues/24)) ([81caebc](https://github.com/rvagg/js-ipld-schema-describer/commit/81caebc7af4b901a97f4712831cf985b36a1cd39))
23
+ * **no-release:** bump actions/setup-node from 3.2.0 to 3.3.0 ([#25](https://github.com/rvagg/js-ipld-schema-describer/issues/25)) ([4da7e2c](https://github.com/rvagg/js-ipld-schema-describer/commit/4da7e2c9e85997603a58d2ff26615be2d6e549b6))
24
+ * **no-release:** bump actions/setup-node from 3.3.0 to 3.4.0 ([#27](https://github.com/rvagg/js-ipld-schema-describer/issues/27)) ([a6d1ecb](https://github.com/rvagg/js-ipld-schema-describer/commit/a6d1ecbe2ed18388f40455a9485251bc6c358b70))
25
+ * **no-release:** bump actions/setup-node from 3.4.0 to 3.4.1 ([#28](https://github.com/rvagg/js-ipld-schema-describer/issues/28)) ([18bd605](https://github.com/rvagg/js-ipld-schema-describer/commit/18bd605284572fd18345021a240a92246df357d9))
26
+
27
+ ### [1.0.10](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.9...v1.0.10) (2022-05-03)
28
+
29
+
30
+ ### Trivial Changes
31
+
32
+ * **deps-dev:** bump mocha from 9.2.2 to 10.0.0 ([821e3e7](https://github.com/rvagg/js-ipld-schema-describer/commit/821e3e741b3c1cb4e09a113f1ef371054ee9f635))
33
+ * **deps:** bump ipld-schema from 1.1.6 to 2.0.1 ([129962f](https://github.com/rvagg/js-ipld-schema-describer/commit/129962f675c5d3f6e5b20bd8d0913eef3bb60715))
34
+ * **no-release:** bump actions/checkout from 2.4.0 to 3 ([#18](https://github.com/rvagg/js-ipld-schema-describer/issues/18)) ([745c567](https://github.com/rvagg/js-ipld-schema-describer/commit/745c5677750506af5af7def747a3e5a2df94b608))
35
+ * **no-release:** bump actions/setup-node from 2.5.0 to 2.5.1 ([#16](https://github.com/rvagg/js-ipld-schema-describer/issues/16)) ([2df4709](https://github.com/rvagg/js-ipld-schema-describer/commit/2df470989f326cacc10bfe3209251e844864d986))
36
+ * **no-release:** bump actions/setup-node from 2.5.1 to 3.0.0 ([#17](https://github.com/rvagg/js-ipld-schema-describer/issues/17)) ([34aaaf8](https://github.com/rvagg/js-ipld-schema-describer/commit/34aaaf85cb915fbbac7298e7380fcb6b14a479cd))
37
+ * **no-release:** bump actions/setup-node from 3.0.0 to 3.1.0 ([#19](https://github.com/rvagg/js-ipld-schema-describer/issues/19)) ([a6965ba](https://github.com/rvagg/js-ipld-schema-describer/commit/a6965ba4c2891f41a086f3db2094978c21c66aac))
38
+ * **no-release:** bump actions/setup-node from 3.1.0 to 3.1.1 ([#20](https://github.com/rvagg/js-ipld-schema-describer/issues/20)) ([6851b6c](https://github.com/rvagg/js-ipld-schema-describer/commit/6851b6c1cda45150171ce4dfc7700b9970c32b3e))
39
+ * **no-release:** bump polendina from 2.0.15 to 3.0.0 ([#23](https://github.com/rvagg/js-ipld-schema-describer/issues/23)) ([44570a3](https://github.com/rvagg/js-ipld-schema-describer/commit/44570a32e66c3ade1b5567a1019326c2af9f3e93))
40
+ * **no-release:** bump standard from 16.0.4 to 17.0.0 ([#21](https://github.com/rvagg/js-ipld-schema-describer/issues/21)) ([baf8f6c](https://github.com/rvagg/js-ipld-schema-describer/commit/baf8f6ca17f74af5ed16811381d0d84c3fdc6f7f))
41
+
42
+ ### [1.0.9](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.8...v1.0.9) (2021-12-08)
43
+
44
+
45
+ ### Trivial Changes
46
+
47
+ * **deps-dev:** bump polendina from 1.1.1 to 2.0.0 ([#15](https://github.com/rvagg/js-ipld-schema-describer/issues/15)) ([8cd6797](https://github.com/rvagg/js-ipld-schema-describer/commit/8cd679789a72da057d2a199437bb4c00f4db22d9))
48
+ * **no-release:** bump actions/checkout from 2.3.4 to 2.4.0 ([#13](https://github.com/rvagg/js-ipld-schema-describer/issues/13)) ([e13e0ba](https://github.com/rvagg/js-ipld-schema-describer/commit/e13e0baeb5e968645405536e36637c3e4774ca37))
49
+ * **no-release:** bump actions/setup-node from 2.4.1 to 2.5.0 ([#14](https://github.com/rvagg/js-ipld-schema-describer/issues/14)) ([7ed1d18](https://github.com/rvagg/js-ipld-schema-describer/commit/7ed1d1828be472f6d2ba776455574ef69369b1d3))
50
+
51
+ ### [1.0.8](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.7...v1.0.8) (2021-09-28)
52
+
53
+
54
+ ### Trivial Changes
55
+
56
+ * **deps:** bump actions/setup-node from 2.4.0 to 2.4.1 ([084039f](https://github.com/rvagg/js-ipld-schema-describer/commit/084039f58353295647bf983b381825903a380f5c))
57
+
58
+ ### [1.0.7](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.6...v1.0.7) (2021-08-06)
59
+
60
+
61
+ ### Trivial Changes
62
+
63
+ * **deps:** bump actions/setup-node from 2.3.2 to 2.4.0 ([330e408](https://github.com/rvagg/js-ipld-schema-describer/commit/330e4086ffd73ef7c3d42ae95457d1c530ad4edd))
64
+
65
+ ### [1.0.6](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.5...v1.0.6) (2021-08-05)
66
+
67
+
68
+ ### Trivial Changes
69
+
70
+ * **deps:** bump actions/setup-node from 2.3.1 to 2.3.2 ([5753f6f](https://github.com/rvagg/js-ipld-schema-describer/commit/5753f6f0490f29c23029b1a1e843f983d453d255))
71
+
72
+ ### [1.0.5](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.4...v1.0.5) (2021-08-04)
73
+
74
+
75
+ ### Trivial Changes
76
+
77
+ * **deps:** bump actions/setup-node from 2.3.0 to 2.3.1 ([15bd94b](https://github.com/rvagg/js-ipld-schema-describer/commit/15bd94b2c7a34772db02cabbc3515789b2197ac8))
78
+
79
+ ### [1.0.4](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.3...v1.0.4) (2021-07-28)
80
+
81
+
82
+ ### Trivial Changes
83
+
84
+ * **deps:** bump actions/setup-node from 2.2.0 to 2.3.0 ([49cdefb](https://github.com/rvagg/js-ipld-schema-describer/commit/49cdefbfdcaef6e32b49bbaf45a71eeca7a798ab))
85
+ * update deps, fix build for latest ipjs ([8bef720](https://github.com/rvagg/js-ipld-schema-describer/commit/8bef72014021f91012beed570d6bc17fbc5179b1))
86
+
87
+ ### [1.0.3](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.2...v1.0.3) (2021-07-01)
88
+
89
+
90
+ ### Trivial Changes
91
+
92
+ * **deps:** bump actions/setup-node from 2.1.5 to 2.2.0 ([c892d3a](https://github.com/rvagg/js-ipld-schema-describer/commit/c892d3a620b6a17fabedf1a0b4a28622af583ec6))
93
+
94
+ ### [1.0.2](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.1...v1.0.2) (2021-06-25)
95
+
96
+
97
+ ### Bug Fixes
98
+
99
+ * export types properly ([908506a](https://github.com/rvagg/js-ipld-schema-describer/commit/908506a4aa750aca1f424d79ce48cf01c3724d3a))
100
+
101
+ ### [1.0.1](https://github.com/rvagg/js-ipld-schema-describer/compare/v1.0.0...v1.0.1) (2021-06-25)
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * release from /dist ([8858183](https://github.com/rvagg/js-ipld-schema-describer/commit/8858183f2d02873845216f403927a87cf5b00f62))
107
+
108
+ ## [1.0.0](https://github.com/rvagg/js-ipld-schema-describer/compare/v0.0.0...v1.0.0) (2021-06-25)
109
+
110
+
111
+ ### ⚠ BREAKING CHANGES
112
+
113
+ * add typing, remove default exports
114
+
115
+ ### Features
116
+
117
+ * add typing, remove default exports ([d972251](https://github.com/rvagg/js-ipld-schema-describer/commit/d9722514c1d6266e19c6022c97b02e62109cdd49))
118
+
119
+
120
+ ### Bug Fixes
121
+
122
+ * separate, minimal windows test run ([31e8d18](https://github.com/rvagg/js-ipld-schema-describer/commit/31e8d18e839321aee37c8ce4f30feea6d49957b5))
123
+
124
+
125
+ ### Trivial Changes
126
+
127
+ * add semantic release & dependabot ([8550947](https://github.com/rvagg/js-ipld-schema-describer/commit/85509479408b2cfbc0f3b2353ed617844c23add9))
package/example.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { describe } from 'ipld-schema-describer'
2
2
  // @ts-ignore
3
- import schemaPrint from 'ipld-schema/print.js'
3
+ import { print as schemaPrint } from 'ipld-schema/print.js'
4
4
 
5
5
  const obj = {
6
6
  foo: [1, 'one', true],
@@ -2,9 +2,9 @@ import { kind } from './kind.js'
2
2
 
3
3
  /**
4
4
  * @typedef {import('ipld-schema/schema-schema').Schema} Schema
5
- * @typedef {import('ipld-schema/schema-schema').TypeLink} TypeLink
6
- * @typedef {import('ipld-schema/schema-schema').TypeList} TypeList
7
- * @typedef {import('ipld-schema/schema-schema').TypeMap} TypeMap
5
+ * @typedef {import('ipld-schema/schema-schema').TypeDefnLink} TypeDefnLink
6
+ * @typedef {import('ipld-schema/schema-schema').TypeDefnList} TypeDefnList
7
+ * @typedef {import('ipld-schema/schema-schema').TypeDefnMap} TypeDefnMap
8
8
  */
9
9
 
10
10
  /**
@@ -18,14 +18,14 @@ export function describe (obj) {
18
18
  // something to point to for our root rather than the plain typed kind
19
19
 
20
20
  // special case for links
21
- if (typeof description.root === 'object' && description.root.kind === 'link') {
21
+ if (typeof description.root === 'object' && typeof description.root.link === 'object') {
22
22
  const name = 'Link'
23
- description.schema.types[name] = { kind: 'link' }
23
+ description.schema.types[name] = { link: {} }
24
24
  description.root = name
25
25
  } else if (typeof description.root === 'string') {
26
26
  const name = `${description.root}`
27
27
  // @ts-ignore
28
- description.schema.types[name] = { kind: description.root.toLowerCase() }
28
+ description.schema.types[name] = { [description.root.toLowerCase()]: {} }
29
29
  description.root = name
30
30
  /* c8 ignore next 3 */
31
31
  } else {
@@ -42,7 +42,7 @@ export function describe (obj) {
42
42
  /**
43
43
  * @param {any} obj
44
44
  * @param {Schema} schema
45
- * @returns {{ schema: Schema, root: string|TypeLink }}
45
+ * @returns {{ schema: Schema, root: string|{ link: TypeDefnLink } }}
46
46
  */
47
47
  function describeObject (obj, schema) {
48
48
  const objKind = kind(obj)
@@ -59,12 +59,12 @@ function describeObject (obj, schema) {
59
59
  }
60
60
 
61
61
  if (objKind === 'link') {
62
- return { schema, root: { kind: 'link' } }
62
+ return { schema, root: { link: {} } }
63
63
  }
64
64
 
65
65
  // 'map' || 'list'
66
66
 
67
- /** @type {{ fieldName: string, root: string|TypeLink }[]} */
67
+ /** @type {{ fieldName: string, root: string|{ link: TypeDefnLink }}[]} */
68
68
  const fieldNames = []
69
69
  const entries = objKind === 'map'
70
70
  ? Object.entries(obj)
@@ -83,32 +83,29 @@ function describeObject (obj, schema) {
83
83
  }
84
84
 
85
85
  name = `${name}_1`
86
- /** @type {{ kind: 'map', keyType?: string, valueType?: string|TypeLink }|{ kind: 'list', valueType?: string|TypeLink}|{ kind: 'struct', fields: { [ k in string]: { type: string | TypeLink } }, representation?: { tuple: {} } }} */
86
+ /** @type {{ map: { keyType?: string, valueType?: string|{ link: TypeDefnLink } } }|{ list: { valueType?: string|{ link: TypeDefnLink } } }|{ struct: { fields: { [ k in string]: { type: string | { link: TypeDefnLink } } }, representation?: { tuple: {} } } } } */
87
87
  let type
88
88
 
89
89
  if (unique) { // a pure map or list
90
- type = { kind: objKind }
91
- if (type.kind === 'map') {
92
- type.keyType = 'String'
93
- }
94
- if (type.kind === 'map' || type.kind === 'list') {
95
- if (fieldNames.length) {
96
- type.valueType = fieldNames[0].root
97
- } else {
98
- type.valueType = 'Any'
99
- }
90
+ const valueType = fieldNames.length ? fieldNames[0].root : 'Any'
91
+ if (objKind === 'map') {
92
+ type = { map: { keyType: 'String', valueType } }
93
+ } else if (objKind === 'list') {
94
+ type = { list: { valueType } }
95
+ /* c8 ignore next 4 */
96
+ } else {
97
+ throw new Error(`Unexpected object kind: ${objKind}`)
100
98
  }
101
99
  } else { // a struct with varying types
102
100
  name = 'Struct_1'
103
101
  type = {
104
- kind: 'struct',
105
- fields: {}
102
+ struct: { fields: {} }
106
103
  }
107
104
  for (const field of fieldNames) {
108
- type.fields[field.fieldName] = { type: field.root }
105
+ type.struct.fields[field.fieldName] = { type: field.root }
109
106
  }
110
107
  if (objKind === 'list') {
111
- type.representation = { tuple: {} }
108
+ type.struct.representation = { tuple: {} }
112
109
  }
113
110
  }
114
111
 
package/package.json CHANGED
@@ -1,26 +1,22 @@
1
1
  {
2
2
  "name": "ipld-schema-describer",
3
- "version": "1.0.8",
3
+ "version": "2.0.0",
4
4
  "description": "IPLD Schema Describer",
5
- "main": "./cjs/ipld-schema-describer.js",
5
+ "main": "ipld-schema-describer.js",
6
+ "type": "module",
6
7
  "types": "./types/ipld-schema-describer.d.ts",
7
8
  "scripts": {
8
9
  "lint": "standard",
9
- "build": "npm run build:js && npm run build:types",
10
- "build:js": "ipjs build --tests --main && npm run build:copy",
11
- "build:copy": "cp -a tsconfig.json *.js dist/",
12
- "build:types": "tsc --build && mv types dist",
13
- "test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js",
10
+ "build": "npm run build:types",
11
+ "build:types": "tsc --build",
14
12
  "test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js",
15
- "test:browser": "polendina --cleanup dist/cjs/node-test/test-*.js",
16
- "test": "npm run lint && npm run test:node && npm run test:cjs && npm run test:browser",
13
+ "test:browser": "polendina --cleanup test/test-*.js",
14
+ "test": "npm run lint && npm run build && npm run test:node && npm run test:browser",
17
15
  "coverage": "c8 --reporter=html mocha test/test-*.js && npx st -d coverage -p 8080"
18
16
  },
19
17
  "exports": {
20
18
  ".": {
21
- "browser": "./esm/ipld-schema-describer.js",
22
- "require": "./cjs/ipld-schema-describer.js",
23
- "import": "./esm/ipld-schema-describer.js"
19
+ "import": "./ipld-schema-describer.js"
24
20
  }
25
21
  },
26
22
  "repository": {
@@ -38,16 +34,15 @@
38
34
  },
39
35
  "homepage": "https://github.com/rvagg/js-ipld-schema-describer#readme",
40
36
  "devDependencies": {
41
- "c8": "^7.7.3",
42
- "chai": "^4.3.4",
43
- "ipjs": "^5.0.4",
44
- "mocha": "^9.0.3",
45
- "polendina": "^1.1.0",
46
- "standard": "^16.0.3",
47
- "typescript": "^4.3.5"
37
+ "c8": "^7.12.0",
38
+ "chai": "^4.3.6",
39
+ "mocha": "^10.0.0",
40
+ "polendina": "^3.1.0",
41
+ "standard": "^17.0.0",
42
+ "typescript": "^4.7.4"
48
43
  },
49
44
  "dependencies": {
50
- "ipld-schema": "^1.1.3"
45
+ "ipld-schema": "^3.0.2"
51
46
  },
52
47
  "typesVersions": {
53
48
  "*": {
@@ -135,17 +130,9 @@
135
130
  }
136
131
  ],
137
132
  "@semantic-release/changelog",
138
- [
139
- "@semantic-release/npm",
140
- {
141
- "pkgRoot": "dist"
142
- }
143
- ],
133
+ "@semantic-release/npm",
144
134
  "@semantic-release/github",
145
135
  "@semantic-release/git"
146
136
  ]
147
- },
148
- "browser": {
149
- ".": "./cjs/ipld-schema-describer.js"
150
137
  }
151
138
  }
@@ -0,0 +1,253 @@
1
+ /* eslint-env mocha */
2
+
3
+ import { describe as describeSchema } from 'ipld-schema-describer'
4
+ import chai from 'chai'
5
+
6
+ const { assert } = chai
7
+
8
+ const fauxCID = {}
9
+ fauxCID.asCID = fauxCID
10
+
11
+ function verify (obj, expected) {
12
+ const description = describeSchema(obj)
13
+ assert.deepEqual(description, expected)
14
+ }
15
+
16
+ describe('Basics', () => {
17
+ it('null', () => {
18
+ const expected = { schema: { types: { Null: { null: {} } } }, root: 'Null' }
19
+ verify(null, expected)
20
+ })
21
+
22
+ it('bool', () => {
23
+ const expected = { schema: { types: { Bool: { bool: {} } } }, root: 'Bool' }
24
+ verify(true, expected)
25
+ verify(false, expected)
26
+ })
27
+
28
+ it('int', () => {
29
+ const expected = { schema: { types: { Int: { int: {} } } }, root: 'Int' }
30
+ verify(101, expected)
31
+ verify(-101, expected)
32
+ verify(0, expected)
33
+ })
34
+
35
+ it('float', () => {
36
+ const expected = { schema: { types: { Float: { float: {} } } }, root: 'Float' }
37
+ verify(1.01, expected)
38
+ verify(-1.01, expected)
39
+ })
40
+
41
+ it('string', () => {
42
+ const expected = { schema: { types: { String: { string: {} } } }, root: 'String' }
43
+ verify('a string', expected)
44
+ verify('', expected)
45
+ })
46
+
47
+ it('link', () => {
48
+ const expected = { schema: { types: { Link: { link: {} } } }, root: 'Link' }
49
+ verify(fauxCID, expected)
50
+ })
51
+
52
+ it('bytes', () => {
53
+ const expected = { schema: { types: { Bytes: { bytes: {} } } }, root: 'Bytes' }
54
+ verify(Uint8Array.from([1, 3, 4, 5]), expected)
55
+ verify(Uint8Array.from([]), expected)
56
+ })
57
+
58
+ it('map', () => {
59
+ const obj = { s1: 'a string', s2: 'second string', s3: 'third string' }
60
+ const expected = {
61
+ schema: {
62
+ types: {
63
+ Map_1: {
64
+ map: {
65
+ keyType: 'String',
66
+ valueType: 'String'
67
+ }
68
+ }
69
+ }
70
+ },
71
+ root: 'Map_1'
72
+ }
73
+ verify(obj, expected)
74
+ })
75
+
76
+ it('empty map', () => {
77
+ const obj = {}
78
+ const expected = {
79
+ schema: {
80
+ types: {
81
+ Map_1: {
82
+ map: {
83
+ keyType: 'String',
84
+ valueType: 'Any'
85
+ }
86
+ }
87
+ }
88
+ },
89
+ root: 'Map_1'
90
+ }
91
+ verify(obj, expected)
92
+ })
93
+
94
+ it('struct (map repr)', () => {
95
+ const obj = { s: 'a string', i: 101, l: fauxCID }
96
+ const expected = {
97
+ schema: {
98
+ types: {
99
+ Struct_1: {
100
+ struct: {
101
+ fields: {
102
+ s: { type: 'String' },
103
+ i: { type: 'Int' },
104
+ l: { type: { link: {} } }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ },
110
+ root: 'Struct_1'
111
+ }
112
+ verify(obj, expected)
113
+ })
114
+
115
+ it('list', () => {
116
+ const obj = ['a string', 'second string', 'third string']
117
+ const expected = {
118
+ schema: {
119
+ types: {
120
+ List_1: {
121
+ list: {
122
+ valueType: 'String'
123
+ }
124
+ }
125
+ }
126
+ },
127
+ root: 'List_1'
128
+ }
129
+ verify(obj, expected)
130
+ })
131
+
132
+ it('empty list', () => {
133
+ const obj = []
134
+ const expected = {
135
+ schema: {
136
+ types: {
137
+ List_1: {
138
+ list: {
139
+ valueType: 'Any'
140
+ }
141
+ }
142
+ }
143
+ },
144
+ root: 'List_1'
145
+ }
146
+ verify(obj, expected)
147
+ })
148
+
149
+ it('struct (list repr)', () => {
150
+ const obj = ['a string', 101, false, null]
151
+ const expected = {
152
+ schema: {
153
+ types: {
154
+ Struct_1: {
155
+ struct: {
156
+ fields: {
157
+ f0: { type: 'String' },
158
+ f1: { type: 'Int' },
159
+ f2: { type: 'Bool' },
160
+ f3: { type: 'Null' }
161
+ },
162
+ representation: { tuple: {} }
163
+ }
164
+ }
165
+ }
166
+ },
167
+ root: 'Struct_1'
168
+ }
169
+ verify(obj, expected)
170
+ })
171
+ })
172
+
173
+ describe('Complex', () => {
174
+ it('list of lists', () => {
175
+ const sa = ['a string', 'second string', 'third string']
176
+ const obj = [sa, sa.slice(), sa.slice()]
177
+ const expected = {
178
+ schema: {
179
+ types: {
180
+ List_1: {
181
+ list: {
182
+ valueType: 'String'
183
+ }
184
+ },
185
+ List_2: {
186
+ list: {
187
+ valueType: 'List_1'
188
+ }
189
+ }
190
+ }
191
+ },
192
+ root: 'List_2'
193
+ }
194
+ verify(obj, expected)
195
+ })
196
+
197
+ it('map of maps', () => {
198
+ const sm = { s1: 'a string', s2: 'second string', s3: 'third string' }
199
+ const obj = { sm1: sm, sm2: Object.assign({}, sm), sm3: Object.assign({}, sm) }
200
+ const expected = {
201
+ schema: {
202
+ types: {
203
+ Map_1: {
204
+ map: {
205
+ keyType: 'String',
206
+ valueType: 'String'
207
+ }
208
+ },
209
+ Map_2: {
210
+ map: {
211
+ keyType: 'String',
212
+ valueType: 'Map_1'
213
+ }
214
+ }
215
+ }
216
+ },
217
+ root: 'Map_2'
218
+ }
219
+ verify(obj, expected)
220
+ })
221
+
222
+ it('struct of structs', () => {
223
+ const obj = ['a string', 101, ['s', false], ['', true]]
224
+ const expected = {
225
+ schema: {
226
+ types: {
227
+ Struct_1: {
228
+ struct: {
229
+ fields: {
230
+ f0: { type: 'String' },
231
+ f1: { type: 'Bool' }
232
+ },
233
+ representation: { tuple: {} }
234
+ }
235
+ },
236
+ Struct_2: {
237
+ struct: {
238
+ fields: {
239
+ f0: { type: 'String' },
240
+ f1: { type: 'Int' },
241
+ f2: { type: 'Struct_1' },
242
+ f3: { type: 'Struct_1' }
243
+ },
244
+ representation: { tuple: {} }
245
+ }
246
+ }
247
+ }
248
+ },
249
+ root: 'Struct_2'
250
+ }
251
+ verify(obj, expected)
252
+ })
253
+ })
@@ -0,0 +1,12 @@
1
+ /* eslint-env mocha */
2
+
3
+ import { describe as describeSchema } from 'ipld-schema-describer'
4
+ import chai from 'chai'
5
+
6
+ const { assert } = chai
7
+
8
+ describe('Errors', () => {
9
+ it('bad kind', () => {
10
+ assert.throws(() => describeSchema(undefined), /Unknown IPLD kind for value: undefined/)
11
+ })
12
+ })
package/tsconfig.json CHANGED
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "exclude": [
35
35
  "node_modules",
36
- "dist",
36
+ "types",
37
37
  "test"
38
38
  ],
39
39
  "compileOnSave": false