@open-captable/cli 0.0.0-stage → 0.2.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.
- package/LICENSE.md +60 -0
- package/README.md +85 -2
- package/build/ObjectTypeSchemaMap.js +146 -0
- package/build/SchemaComposer.js +835 -0
- package/build/SchemaDereferencer.js +207 -0
- package/build/schemas.json +1 -0
- package/cli.mjs +97 -0
- package/lib/export.mjs +148 -0
- package/lib/input.mjs +29 -0
- package/lib/remote.mjs +102 -0
- package/lib/schema.mjs +147 -0
- package/package.json +38 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
### Schema and Documentation License
|
|
2
|
+
|
|
3
|
+
Version 1.0.1, April 3, 2024
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2024 Open Cap Table Coalition <https://opencaptablecoalition.com/>
|
|
6
|
+
|
|
7
|
+
#### 1. LICENSE
|
|
8
|
+
|
|
9
|
+
**By using and/or copying Open Cap Table Coalition JSON Schema files or documentation thereof
|
|
10
|
+
(each, individually, an “OCF File”, and, collectively, the “OCF Files”), you (the licensee)
|
|
11
|
+
agree that you have read, understood, and will comply with the following terms and conditions**:
|
|
12
|
+
|
|
13
|
+
Permission to copy and distribute OCF Files, in any medium for any purpose and without fee or
|
|
14
|
+
royalty is hereby granted, provided that
|
|
15
|
+
|
|
16
|
+
1. For _ALL_ copies of an OCF File or portions thereof that are **not** JSON Schema files, you include
|
|
17
|
+
|
|
18
|
+
- A link to the original OCF File and
|
|
19
|
+
- A notice in the form "Copyright © [$date-of-ocf-file] [Open Cap Table Coalition](https://opencaptablecoalition.com)."; and
|
|
20
|
+
|
|
21
|
+
2. For _ALL_ copies of an OCF File or portions thereof that **are** JSON Schema files, you include
|
|
22
|
+
|
|
23
|
+
- A `$comment` field with a value of: "Copyright © [$date-of-ocf-file]
|
|
24
|
+
Open Cap Table Coalition (https://opencaptablecoalition.com) / Original File: [$url-of-original-schema-file]"
|
|
25
|
+
|
|
26
|
+
When space permits, inclusion of the full text of the **NOTICE** (as defined below) should be provided. We request
|
|
27
|
+
that authorship attribution be provided in any software, documents, or other items or products
|
|
28
|
+
that you create pursuant to the implementation of OCF Files, or any portion thereof.
|
|
29
|
+
|
|
30
|
+
No right to create modifications or derivatives of OCF Files is granted pursuant to this license,
|
|
31
|
+
except as follows:
|
|
32
|
+
|
|
33
|
+
_To facilitate implementation of the technical specifications set forth in
|
|
34
|
+
the OCF Files, anyone may prepare and distribute derivative works and
|
|
35
|
+
portions of the OCF Files in software, in supporting materials accompanying
|
|
36
|
+
software, and in documentation of software, PROVIDED that all such
|
|
37
|
+
works include the notice below. HOWEVER, the publication of derivative
|
|
38
|
+
works of OCF Files for use as a technical specification is expressly prohibited._
|
|
39
|
+
|
|
40
|
+
In addition, "Code Components" — sample OCF file implementations, sample OCF JSONs and computer
|
|
41
|
+
programming language code — are licensed under the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0).
|
|
42
|
+
|
|
43
|
+
The full "Notice" is:
|
|
44
|
+
|
|
45
|
+
> "Copyright © [$date-of-ocf-file] Open Cap Table Coalition. This software or document
|
|
46
|
+
> includes material copied from or derived from [title and URI of the OCF File]."
|
|
47
|
+
|
|
48
|
+
#### 2. DISCLAIMERS
|
|
49
|
+
|
|
50
|
+
OCF FILES ARE PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES,
|
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
52
|
+
FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE OCF FILES ARE
|
|
53
|
+
SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY
|
|
54
|
+
THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE
|
|
55
|
+
FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE OCF FILES
|
|
56
|
+
OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF.
|
|
57
|
+
|
|
58
|
+
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining
|
|
59
|
+
to the OCF Files or their contents without specific, written prior permission. Title to copyright
|
|
60
|
+
in the OCF Files will at all times remain with copyright holders.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-captable/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Author OCF objects for a specific schema release from the command line. The package includes the OCF
|
|
4
|
+
1.2.0 schemas and validates offline.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
ocf describe STAKEHOLDER
|
|
8
|
+
echo '{"id":"p1","stakeholder_type":"INDIVIDUAL","name":{"legal_name":"A. Lee"}}' | ocf object STAKEHOLDER >> records.jsonl
|
|
9
|
+
ocf validate records.jsonl
|
|
10
|
+
ocf validate --schema-dir ./schema --format jsonl - < records.jsonl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Supply field values on stdin or with `--in file.json`. The object command supplies the discriminator
|
|
14
|
+
and emits one compact JSON record after validation. Validation accepts a JSON object, an array, or
|
|
15
|
+
one object per nonblank JSONL line. Use `--format jsonl` for JSONL on stdin. Errors go to stderr
|
|
16
|
+
with a nonzero exit code. Add `--json` for structured errors.
|
|
17
|
+
|
|
18
|
+
From a repository checkout with the v1.2.0 tag available, run `npm ci` and `npm test` in
|
|
19
|
+
`packages/cli`. Run the built CLI with `node cli.mjs`. The build compiles the repository’s schema
|
|
20
|
+
composition and object type routing utilities and packages the pinned release schemas with their
|
|
21
|
+
original IDs and notices.
|
|
22
|
+
|
|
23
|
+
## Assemble an export
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
ocf export records.jsonl --issuer issuer.json --as-of 2024-12-31 --out ./export
|
|
27
|
+
ocf validate ./export
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Supply a complete OCF issuer object. The input can also be stdin, a JSON array, or a directory
|
|
31
|
+
containing JSON and JSONL files. Directory inputs are read in filename order, skipping the
|
|
32
|
+
separately supplied issuer file. Record order is preserved within each category. Use a new or empty
|
|
33
|
+
output directory.
|
|
34
|
+
|
|
35
|
+
The writer stages a manifest and typed files, verifies their schemas and MD5 checksums, then
|
|
36
|
+
publishes the directory. Directory validation starts at `Manifest.ocf.json` and checks each
|
|
37
|
+
referenced file against its manifest category. Validating an individual OCF file checks its schema
|
|
38
|
+
only.
|
|
39
|
+
|
|
40
|
+
## Select schemas
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
ocf validate ./export --ocf-version 1.2.0
|
|
44
|
+
ocf describe VESTING_TERMS --schema-ref main
|
|
45
|
+
ocf describe STAKEHOLDER --schema-ref v1.0.0-b2
|
|
46
|
+
ocf export records.jsonl --issuer issuer.json --as-of 2024-12-31 --out ./export --schema-dir ./schema
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
All commands accept one schema source. For `--ocf-version`, the CLI lists schema filenames from the
|
|
50
|
+
matching GitHub release tag and downloads their contents from the Coalition’s versioned schema URIs.
|
|
51
|
+
For `--schema-ref`, supply a branch (including names containing slashes), tag, or full commit SHA in
|
|
52
|
+
the Coalition's OCF GitHub repository. The CLI reports the resolved SHA on stderr and reads every
|
|
53
|
+
schema from that commit. References resolve against the selected snapshot even when their declared
|
|
54
|
+
IDs point to main or to a release URI.
|
|
55
|
+
|
|
56
|
+
Complete downloads are cached in `$XDG_CACHE_HOME/open-captable/faker` (default
|
|
57
|
+
`~/.cache/open-captable/faker`). A cached release version or full SHA works offline. Named GitHub
|
|
58
|
+
refs are resolved on each run so a moving branch picks up new commits.
|
|
59
|
+
|
|
60
|
+
## Stage a CLI release
|
|
61
|
+
|
|
62
|
+
The first release and every tagged release go through npm's staging queue. A maintainer reviews the
|
|
63
|
+
tarball in **Staged Packages** on npmjs.com and approves it with 2FA to make that version public.
|
|
64
|
+
[Staged publishing](https://docs.npmjs.com/staged-publishing/)
|
|
65
|
+
|
|
66
|
+
For the first release, run `release-cli.yml` manually on `main` and download and extract the
|
|
67
|
+
`cli-npm` artifact. From the extracted directory, sign in with an account that has write access to
|
|
68
|
+
`@open-captable` and stage the tested tarball. Use Node 22.14+ and npm 11.15+.
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm login
|
|
72
|
+
npm stage publish ./open-captable-cli-0.2.0.tgz --access public --tag latest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For a new package, npm creates a public `0.0.0-stage` placeholder. The contents of the staged
|
|
76
|
+
version become public when a maintainer approves it.
|
|
77
|
+
|
|
78
|
+
For automated staging, configure the package's GitHub Actions trusted publisher for
|
|
79
|
+
`Open-Cap-Table-Coalition/Open-Cap-Format-OCF`, workflow `release-cli.yml`. Grant only
|
|
80
|
+
`npm stage publish` permission. Leave direct publishing and dist-tag management disabled.
|
|
81
|
+
[npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
|
|
82
|
+
|
|
83
|
+
The CLI version is independent of the bundled OCF version. For subsequent releases, update it in
|
|
84
|
+
`packages/cli` with `npm version --no-git-tag-version <version>`, commit the package manifest and
|
|
85
|
+
lockfile, and push the matching tag (for example, `cli-v0.2.1`). CI stages the tested artifact with
|
|
86
|
+
the npm tag `latest` for stable releases or `next` for prereleases.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectTypeSchemaMap
|
|
3
|
+
*
|
|
4
|
+
* Builds the `object_type` -> schema `$id` lookup the validator uses to pick
|
|
5
|
+
* which schema an OCF item should be validated against. Extracted from
|
|
6
|
+
* `validate.mjs` as a pure, framework-free function so it can be unit-tested
|
|
7
|
+
* and so all three wrapper-aware call sites (validator, doc generator,
|
|
8
|
+
* composer) agree on the schema conventions.
|
|
9
|
+
*
|
|
10
|
+
* Three schema shapes are recognized:
|
|
11
|
+
*
|
|
12
|
+
* 1. Ordinary object schemas (including backwards-compatibility wrappers,
|
|
13
|
+
* which carry their own `object_type` const) — map each `object_type`
|
|
14
|
+
* const/enum value to the schema's own `$id`. A wrapper's `$id` and the
|
|
15
|
+
* schema it aliases both validate the same data via the wrapper's `allOf`
|
|
16
|
+
* ref, so it does not matter which wins a shared `object_type`.
|
|
17
|
+
* 2. Property-less single-`allOf` wrappers — ignored: with no `object_type`
|
|
18
|
+
* of their own, the schema they alias produces the mapping instead.
|
|
19
|
+
* 3. Version dispatchers (VersionWrapper: an `anyOf` of `$ref`s, no own
|
|
20
|
+
* properties) — map every `object_type` of every referenced versioned
|
|
21
|
+
* shape to the DISPATCHER's public `$id`. Validating against the
|
|
22
|
+
* dispatcher (an `anyOf`) accepts any active version during a transition
|
|
23
|
+
* window, which is the whole point of the pattern. The referenced
|
|
24
|
+
* versioned shapes are therefore NOT mapped to their own `$id`.
|
|
25
|
+
*
|
|
26
|
+
* When a `registry` is supplied, a dispatcher's versioned shapes are COMPOSED
|
|
27
|
+
* (their `allOf` chain flattened) before their `object_type` is read, so the
|
|
28
|
+
* validator resolves it exactly as the doc generator does — a versioned shape
|
|
29
|
+
* may then live in any partition and inherit `object_type` through `allOf`
|
|
30
|
+
* rather than being forced to re-declare it inline. Without a registry the raw
|
|
31
|
+
* shape is read (the pure-function default used by unit tests).
|
|
32
|
+
*/
|
|
33
|
+
import { composeSchema, isVersionWrapper, objectTypeValues, versionRefsOf, versionShapeOwnerMap, } from "./SchemaComposer.js";
|
|
34
|
+
export function buildObjectTypeSchemaMap(objectSchemas, allowedObjectTypes, options = {}) {
|
|
35
|
+
const { verbose = false, registry } = options;
|
|
36
|
+
const allowed = new Set(allowedObjectTypes);
|
|
37
|
+
const map = {};
|
|
38
|
+
const byId = {};
|
|
39
|
+
for (const schema of objectSchemas) {
|
|
40
|
+
if (schema && typeof schema.$id === "string")
|
|
41
|
+
byId[schema.$id] = schema;
|
|
42
|
+
}
|
|
43
|
+
// Memoizes composition of versioned shapes across a dispatcher's refs.
|
|
44
|
+
const composeCache = new Map();
|
|
45
|
+
/** Resolve a dispatcher's versioned-shape `$ref` to the schema whose
|
|
46
|
+
* `object_type` should be read. Prefer the full `registry` (so a shape in
|
|
47
|
+
* any partition resolves, and its `allOf` chain is composed exactly as the
|
|
48
|
+
* doc generator composes it); fall back to the raw object-partition schema. */
|
|
49
|
+
const resolveVersionShape = (ref) => {
|
|
50
|
+
const raw = registry?.[ref] ?? byId[ref];
|
|
51
|
+
if (!raw)
|
|
52
|
+
return undefined;
|
|
53
|
+
return registry ? composeSchema(raw, registry, composeCache, "skip") : raw;
|
|
54
|
+
};
|
|
55
|
+
// Which schemas are versioned shapes owned by a dispatcher? Their
|
|
56
|
+
// object_type is mapped to the dispatcher, not to their own $id. Built by the
|
|
57
|
+
// same shared helper the doc generator and codegen use, so all three agree.
|
|
58
|
+
const versionShapeOwner = versionShapeOwnerMap(objectSchemas);
|
|
59
|
+
const assign = (objectType, schemaId, context) => {
|
|
60
|
+
if (!allowed.has(objectType)) {
|
|
61
|
+
throw new Error(`Encountered object_type: ${objectType} in ${context} but this type does not exist in ObjectType.schema.json`);
|
|
62
|
+
}
|
|
63
|
+
map[objectType] = schemaId;
|
|
64
|
+
};
|
|
65
|
+
for (const schema of objectSchemas) {
|
|
66
|
+
// (3) Version dispatcher: map each versioned shape's object_type(s) to the
|
|
67
|
+
// dispatcher's public $id.
|
|
68
|
+
if (isVersionWrapper(schema)) {
|
|
69
|
+
for (const ref of versionRefsOf(schema)) {
|
|
70
|
+
const shape = resolveVersionShape(ref);
|
|
71
|
+
if (!shape) {
|
|
72
|
+
throw new Error(`Version dispatcher ${schema.$id} references unknown version shape ${ref}`);
|
|
73
|
+
}
|
|
74
|
+
const values = objectTypeValues(shape.properties?.object_type);
|
|
75
|
+
if (values.length === 0) {
|
|
76
|
+
throw new Error(`Version shape ${ref} (referenced by dispatcher ${schema.$id}) has no object_type const/enum`);
|
|
77
|
+
}
|
|
78
|
+
for (const value of values) {
|
|
79
|
+
assign(value, schema.$id, `version dispatcher ${schema.$id}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// A versioned shape owned by a dispatcher — already mapped above.
|
|
85
|
+
if (versionShapeOwner.has(schema.$id)) {
|
|
86
|
+
if (verbose) {
|
|
87
|
+
console.log(`Schema ${schema.$id} is a versioned shape of ${versionShapeOwner.get(schema.$id)}... mapping handled by the dispatcher.`);
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// (1) Ordinary object schema with an object_type property.
|
|
92
|
+
if (schema.properties && schema.properties.object_type) {
|
|
93
|
+
const objectType = schema.properties.object_type;
|
|
94
|
+
if (typeof objectType === "object" &&
|
|
95
|
+
!Array.isArray(objectType) &&
|
|
96
|
+
objectType !== null) {
|
|
97
|
+
if (typeof objectType.const === "string") {
|
|
98
|
+
assign(objectType.const, schema.$id, `schema ${schema.$id}`);
|
|
99
|
+
}
|
|
100
|
+
else if (Array.isArray(objectType.enum)) {
|
|
101
|
+
// Backwards-compat alias arrays were never validated against the
|
|
102
|
+
// ObjectType enum here; preserve that behavior.
|
|
103
|
+
for (const item of objectType.enum) {
|
|
104
|
+
if (item)
|
|
105
|
+
map[item] = schema.$id;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// An object_type with neither a const nor an enum is not a shape
|
|
110
|
+
// this map can key on. The original validator logged and CONTINUED
|
|
111
|
+
// (it did not throw) so one odd schema would not abort the run;
|
|
112
|
+
// preserve that tolerance rather than hard-failing CI.
|
|
113
|
+
console.error(`Unexpected value for object_type in schema ${schema.$id}; skipping (no const/enum to map).`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.error(`Unexpected value for object_type in schema ${schema.$id}; skipping (object_type is not an object).`);
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// (2) Property-less single-allOf wrapper — ignored; with no object_type of
|
|
122
|
+
// its own, the schema it aliases produces the mapping instead.
|
|
123
|
+
if (schema.$id &&
|
|
124
|
+
Array.isArray(schema.allOf) &&
|
|
125
|
+
schema.allOf.length === 1 &&
|
|
126
|
+
!schema.properties) {
|
|
127
|
+
if (verbose) {
|
|
128
|
+
console.log(`Appears schema ${schema.$id} is a wrapper for ${schema.allOf?.[0]?.$ref}... ignoring.`);
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
// A schema that HAS properties but no object_type contributes no mapping;
|
|
133
|
+
// the original validator passed over it silently rather than failing, so
|
|
134
|
+
// do the same (a schema can legitimately lack an object_type).
|
|
135
|
+
if (schema.properties) {
|
|
136
|
+
if (verbose) {
|
|
137
|
+
console.log(`Schema ${schema.$id} has properties but no object_type; nothing to map.`);
|
|
138
|
+
}
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// No properties and not a single-allOf wrapper: genuinely unrecognized.
|
|
142
|
+
// The original validator threw here, so keep failing loudly.
|
|
143
|
+
throw new Error(`Schema ${schema.$id} doesn't match OCF schema format and it's not a wrapper`);
|
|
144
|
+
}
|
|
145
|
+
return map;
|
|
146
|
+
}
|