Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
pull_request:
push:
branches: [master, proposed_type_script_api_version]
branches: [master]

permissions:
contents: read
Expand Down
110 changes: 110 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,115 @@
# Changelog

## 1.0.0-alpha.7 — what a browser app consumer asked for

One breaking change, to attachments; everything else is additive. Each
entry says what a consumer changes, if anything.

### Breaking

- **An attachment is answered as a row of the Attachment type**, under
meta.v1's attribute names like every other row, plus `id`. It was the
one place the SDK had a vocabulary of its own. This holds for
`client.attachments.list`, `page`, `info`, `get` and `add`, and for
`AttachmentUploadError.attachment`. Migration, field by field:
- `oid` → `_oid`
- `id` → `id` (unchanged: the number attachment.img addresses)
- `name` → `Name`; `filename` → `Filename`; `description` →
`Description`; `createDate` → `CreateDate`
- `contentType` → `ContentType` (the recorded one)
- `createdBy` → `["CreatedBy.Name"]` (the select path, as selected)
- on `get`: `contentType` (the served type, falling back to the
recorded one) → `servedContentType ?? ContentType`;
`recordedContentType` → `ContentType`
`add`'s options (`filename`, `contentType`, `name`, `description`,
`inlineLimit`) are unchanged. The row type is closed (it does not
extend `Asset`): it has these keys and the ones a `select` named, so a
read the migration missed (`row.filename`) is a compile error rather
than `undefined`.

### Added

- **`client.attachments.list` / `page` take a `select`**: more to read
with each attachment, as a query's `select` on Attachment
(`Category.Name`, `Asset.Number`, a sub-select). Each row then carries
those keys too, as selected, translated like any row and typed by what
was selected. Migration: a second query for an attachment's other
attributes becomes `list(asset, { select })`.
- **A one-request read for a small attachment**:
`client.attachments.get(id, { inline: true })` reads the metadata and
the bytes in one query.v1 request (the Attachment's `Content` comes
back as Base64 beside its row) where the default is two (the row, then
attachment.img). For small files: the response is a third larger than
the file and is held in memory whole. `servedContentType` is then
null. Migration: none; add `{ inline: true }` where a thumbnail
or a small text file is read.
- **`normalizeQuery(query)`**: a query written with rest-1's spellings
becomes the `QueryBody` every read takes — `sel` → `select`, a textual
`where` → `filter`, comma-joined `select` / `sort` / `findin` → lists,
a `"size,start"` page → `{ size, start }`, sub-selects the same way. A
`QueryBody` comes back equal. Saying one thing twice (`sel` and
`select`) or asking for `deleted` is a `UsageError`. `QueryBody` itself
gains no alias. Migration: a consumer's own `sel`-to-`select` shim
becomes `client.query(normalizeQuery(q))`.
- **`@versionone/agility-sdk/testing`** exports `FakeAgilityClient`: a
real `AgilityApiClient` over a transport that sends nothing. A test
scripts answers in the model's shape (`onQuery("Story", rows)`,
`onSend(outcome)`, `onRequest(path, answer)` for any other endpoint)
and asserts on what was asked (`asked`, `sent`, `requests`). A scripted
list is paged by the fake, a write answers OIDs without a script, and a
read nothing was scripted for throws a `UsageError` instead of reading
as empty. `resolve.numbers` finds a number among the scripted rows,
a query from a create's alias reads the created asset back, `localize`
echoes a tag `onLocalize` did not script, and `fake.transport` can
serve a client the code under test builds itself. It evaluates no
filter and applies no write. Migration: a
hand-written fake client or fake Transport in a consumer's tests can be
replaced by it; nothing requires that.
- **`apiErrorFromResponse(status, data)`**: the `ApiError` the fetch
transport throws for a refused response, exported for a custom
`Transport` to throw, so message, `kind` and `details` are the same
whichever transport sent the request. Migration: a custom transport's
`new ApiError(text, status)` becomes `apiErrorFromResponse(status,
body)`.
- **`@versionone/agility-sdk/wire`**: the wire modules (`assetApi`,
`queryV1`, `rest1`, `meta`, `loc2`, `attachment`, `fields`, `select`)
under their own import path. The root still exports them in this
alpha and stops in the next. Migration: `import { assetApi } from
"@versionone/agility-sdk"` → `from "@versionone/agility-sdk/wire"`.

### Fixed

- **`Outcome.requestId` after `assets.sendGuarded` and `batch.run`** is
the server's id when the batch went out in one request (the usual
case); it was always null. It stays null when the batch took several
sends. (a CLI consumer.) Migration: none.

### Documented

- `Page.more` is the pager's signal: with a total it is exact; when
`total` is null it is whether the page came back full, so a pager
offers "next" on `more`, never on `total`.
- `kind: "usage"` (on `ApiError.kind`): the SDK refused the call before
sending anything — no request reached the server and `status` is 0.
- `ClientConfig.baseUrl` with a custom `Transport`: the transport alone
decides where requests go; `baseUrl` is then used only for the links
the client builds (`client.urls.*`, `embeddedImages.normalize`), so
give it the instance's public URL.
- **For authors of a custom `Transport`** (this should have been under
"Breaking" in alpha.5): a request with `acceptNotModified` must
resolve to `undefined` on a 304, after calling `onResponse` with the
304's status and headers, instead of rejecting. `client.meta.etag`,
`meta.read`, `meta.readType` and `schema.revalidate` send such
requests. And `retries` / `timeoutMs` configure the built-in fetch
transport only: a client given its own Transport resends nothing unless
that transport does.
- `client.meta` answers the model's `Metamodel` / `AssetType`
(references as tokens), not meta.v1's own document; its doc said
"raw".
- `client.query`'s doc said a resend needed `retries` raised from 0 and
that `details` was the whole error document; both changed in alpha.5
and the doc now says so.

## 1.0.0-alpha.6

- The generated model is refreshed from meta.v1 26.3.2.13 (was
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ and consumers pin commits by SHA), and nothing new is added to it.
npm run verify # typecheck, build, unit tests (including the public-tree check)
```

Open the pull request against `proposed_type_script_api_version`. A
change to an invariant changes `specs/000-layers.md` in the same commit.
Open the pull request against `master`. A change to an invariant changes
`specs/000-layers.md` in the same commit, and a change a consumer can see
gets a `CHANGELOG.md` entry with its migration line.
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,54 @@ Changes between alphas are in `CHANGELOG.md`, each with its migration line.

- `AgilityApiClient` - the client. One query body everywhere; the client picks the endpoint:
- `query` / `queries` - rows, translated (numbers as numbers, booleans as booleans, a single relation as one `Ref`), through query.v1: read-only, so a request is retried like a GET. A page is required; a refused query throws, never an empty result. Written with a literal `from`, `select` completes from the type's attributes and the rows are typed by what was selected
- `get(oid, select)` - one asset or null; `queryPage(q)` - rows with the total and whether more follow; `pages(q, { limit })` / `all(q, { limit })` - page by page up to a limit (default 1000); `me()` - the member the credentials belong to
- `get(oid, select)` - one asset or null; `queryPage(q)` - rows with the total and whether more follow (`more` is what a pager reads: when the server reports no total, `total` is null and `more` is whether the page came back full); `pages(q, { limit })` / `all(q, { limit })` - page by page up to a limit (default 1000); `me()` - the member the credentials belong to
- `assets.send` - an api/asset batch, answered as an `Outcome` (`created`, `modified`, `operated`, `failures` with parsed violations, `queryResults`); `throwOnFailure` throws a `CommandFailureError` carrying the same Outcome. `assets.preview` - the projection. `assets.sendGuarded` - a batch as a compare-and-set on each asset's ChangeDate; changed assets come back `skipped`
- `batch.run` / `batch.reversible` - preview, snapshot, (confirm,) send guarded, and a receipt with a reverse batch; undo reactivates a closed asset before deleting it and reopens what a close cascaded to
- `resolve.numbers` / `resolve.ref` - asset numbers and OID tokens to assets, in one request
- `attachments.list` / `page` / `info` / `get` / `add` / `put` / `remove` - files attached to an asset; `add` sends a small file inline and a large one in two steps, and a failed upload throws `AttachmentUploadError` naming the empty attachment it left
- `attachments.list` / `page` / `info` / `get` / `add` / `put` / `remove` - files attached to an asset, each answered as a row of the Attachment type (`_oid`, `Name`, `Filename`, `ContentType`, …) plus `id`, the number its bytes are addressed by; `list` and `page` answer metadata, plus whatever keys a `select` adds; `get` reads metadata and bytes in two requests, or in one with `{ inline: true }` for a small file; `add` sends a small file inline and a large one in two steps, and a failed upload throws `AttachmentUploadError` naming the empty attachment it left
- `embeddedImages.upload` / `normalize` - images in rich text; they cannot be deleted
- `copy(oid)` - the Copy operation, answering the copy's OID (api/asset performs it but never says what it made); `data.operate(oid, op)` is the general form
- `fields.describe(type, scope)` - what a form needs: required attributes (meta), the ones the product shows there (`api/visibleFields`, custom fields included), the scheme's important fields and whether they are enforced at close
- `urls.asset(oidOrNumber)` / `attachment` / `embeddedImage` - where a browser opens each
- `data.list` / `get` / `history` / `template` - rest-1 reads: deleted assets, history, and a new asset's template for a context (`New/<Type>?ctx=`); `meta.*` - meta.v1 raw, with conditional reads (`read` / `readType` with `ifNoneMatch`, `etag()`: meta.v1 sends one ETag for the whole schema); `schema` - the translated, cached view, `schema.revalidate()` drops it only when that tag moves; `localize` - loc-2 labels for tags (a violation's `tag` is one)
- Errors: everything thrown is an `ApiError` with a `kind` (`auth`, `forbidden`, `notFound`, `invalid`, `transient`, `aborted`, `commandFailure`, `protocol`, `usage`, `unknown`). A mistake caught before any request is a `UsageError`
- `normalizeQuery(q)` - a query written with rest-1's spellings (`sel`, a textual `where`, comma-joined lists, a `"size,start"` page) as the `QueryBody` every read takes
- Errors: everything thrown is an `ApiError` with a `kind` (`auth`, `forbidden`, `notFound`, `invalid`, `transient`, `aborted`, `commandFailure`, `protocol`, `usage`, `unknown`). A mistake caught before any request is a `UsageError`: `kind: "usage"` means nothing was sent (`status` is 0), so the fix is in the call, not on the server
- `TypeCache` - one instance's loaded type definitions, shared by many clients (`new AgilityApiClient(config, { types })`)
- `createFetchTransport` - configurable HTTP transport: `credentials` for same-origin cookie auth, `onUnauthorized` to re-authenticate on a 401 (resends idempotent requests once), and a per-request `signal`; `client.withSignal(signal)` ties a whole client to one
- The wire modules (`assetApi`, `queryV1`, `rest1`, `meta`, `loc2`, `attachment`) are exported for passthroughs and transport authors; they speak the endpoints' own shapes
- A custom `Transport` (`new AgilityApiClient(config, { transport })`) decides by itself where requests go; `config.baseUrl` is then used only for the links the client builds (`urls.*`, `embeddedImages.normalize`). `apiErrorFromResponse(status, data)` is the error the fetch transport throws for a refused response, for a custom transport to throw the same
- `@versionone/agility-sdk/wire` - the wire modules (`assetApi`, `queryV1`, `rest1`, `meta`, `loc2`, `attachment`, `fields`, `select`), for passthroughs and transport authors; they speak the endpoints' own shapes. (The root still exports them in this alpha and stops in the next.)

## Testing code that uses the SDK

`@versionone/agility-sdk/testing` exports `FakeAgilityClient`: a real client over a transport that sends nothing and answers what the test scripted, in the shape the client hands your code.

```ts
import { FakeAgilityClient } from "@versionone/agility-sdk/testing";

const fake = new FakeAgilityClient()
.onQuery("Story", [{ _oid: "Story:1", Name: "Logon", Estimate: 2 }]);

await closeStory(fake, "Story:1"); // your code, taking an AgilityApiClient

expect(fake.asked[0]).toMatchObject({ from: "Story:1" }); // what it read
expect(fake.sent[0]).toEqual([{ from: "Story:1", execute: "QuickClose" }]); // what it wrote
```

- `onQuery(match, rows)` answers every read (`query`, `get`, `queryPage`, `pages`, …). A list is the whole result: the fake pages it and answers a read by OID with that row. A function gets the query and answers one page. A read nothing was scripted for throws; it never looks like an empty result.
- Writes need no script: a create answers a new OID, an update or operation by OID answers that OID. `onSend` scripts anything else, failures included.
- `resolve.numbers` finds a number among the scripted rows; `localize` answers `onLocalize` labels and echoes any other tag; `fake.transport` can be the transport of a client your code builds itself.
- `onRequest(path, answer)` answers any other endpoint in its own shape. An `Error` as an answer is thrown.
- The fake evaluates no filter or sort and applies no write. It proves what your code asks and what it does with the answer; what the server answers is for a test against an instance.

API reference: https://docs.digital.ai/agility-api/

## Extend with new APIs
## Adding to the SDK

1. Add a new folder under `src/apis/`.
2. Add request/response types under `src/types/`.
3. Implement methods using `Transport.request`.
4. Export from `src/index.ts`.
5. Add tests under `test/`.
`specs/000-layers.md` says how the code is arranged (types, wire modules, services, core) and what each layer may know; `CONTRIBUTING.md` says what may be committed to this public repository. A new endpoint is a new module under `src/wire/`, with a unit test that fakes the transport with a response copied from a live one and an integration test that proves it against an instance.

## Installing before a release
## Installing an unreleased commit

No registry package yet. Pin a commit: `npm install github:versionone/VersionOne.SDK.JavaScript#<sha>` builds `dist` on install (the `prepare` script). CI also uploads an `npm pack` tarball on every run.
`npm install github:versionone/VersionOne.SDK.JavaScript#<sha>` builds `dist` on install (the `prepare` script). CI also uploads an `npm pack` tarball on every run.

## Releasing

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@versionone/agility-sdk",
"version": "1.0.0-alpha.6",
"version": "1.0.0-alpha.7",
"description": "TypeScript SDK for the Digital.ai Agility (VersionOne) API: queries, batches, schema-translated rows, guarded writes, attachments",
"keywords": [
"agility",
Expand All @@ -26,6 +26,26 @@
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./wire": {
"import": {
"types": "./dist/wire.d.ts",
"default": "./dist/wire.js"
},
"require": {
"types": "./dist/wire.d.cts",
"default": "./dist/wire.cjs"
}
},
"./testing": {
"import": {
"types": "./dist/testing.d.ts",
"default": "./dist/testing.js"
},
"require": {
"types": "./dist/testing.d.cts",
"default": "./dist/testing.cjs"
}
}
},
"files": [
Expand Down
22 changes: 22 additions & 0 deletions specs/000-layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ src/services what to do imports: types, wire, core
src/core transport, errors imports: nothing above it
```

Beside the table, not in it: `src/client.ts` binds the layers into the
client, and `src/testing` (§5a) stands on the client. Nothing imports
`src/testing`.

- **`types`** is the vocabulary: the asset types generated from meta.v1
(`src/types/assets/`, one file per asset type, the `extends` chain from
the metamodel's `Base` chain) and the hand-written roots in
Expand Down Expand Up @@ -151,6 +155,24 @@ index lag, what a preview echoes — are what fakes cannot reproduce; the
integration tier is where a live probe becomes permanent, with an
expect-zero control beside every "it returned rows".

## 5a. Three import paths, and a fake for consumers

The package has three entries: the root (the client, the model, the
services), `/wire` (the wire modules, for passthroughs and transport
authors) and `/testing`. They are built with shared chunks in both module
formats, so a class is one class whichever path imported it; the CommonJS
unit test proves it.

`/testing` holds `FakeAgilityClient`: the real client over a transport
that sends nothing. It is scripted in the **model's** shape, the one shape
of §2, because that is the contract a consumer codes against; it runs with
a schema that knows no type, so scripted rows pass through as written. It
therefore proves nothing about translation or about the server, and says
so: it evaluates no filter, applies no write, and throws for a read
nothing was scripted for (§6: a failure never reads as an empty). The
corollary of §2a still binds this repository's own unit tests, which fake
the *transport* with what the server sends.

## 6. Politeness is in the layer

No read is unbounded: `assetApi.queries` and `queryV1.queries` refuse a
Expand Down
Loading