@jarenjs/contract 0.43.1
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/README.md +508 -0
- package/dist/types/adapters/fetch.d.ts +27 -0
- package/dist/types/adapters/node.d.ts +47 -0
- package/dist/types/app/binding.d.ts +122 -0
- package/dist/types/app/effect.d.ts +77 -0
- package/dist/types/app/index.d.ts +31 -0
- package/dist/types/app/subscription.d.ts +82 -0
- package/dist/types/bundle.d.ts +43 -0
- package/dist/types/cli.d.ts +15 -0
- package/dist/types/client/http.d.ts +242 -0
- package/dist/types/client/outcome.d.ts +289 -0
- package/dist/types/compat.d.ts +36 -0
- package/dist/types/compile.d.ts +196 -0
- package/dist/types/describe.d.ts +115 -0
- package/dist/types/diff.d.ts +91 -0
- package/dist/types/errors.d.ts +205 -0
- package/dist/types/http/dispatch.d.ts +148 -0
- package/dist/types/http/serve.d.ts +154 -0
- package/dist/types/http/wire.d.ts +334 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/ledger.d.ts +207 -0
- package/dist/types/local/index.d.ts +127 -0
- package/dist/types/messages.d.ts +63 -0
- package/dist/types/path.d.ts +119 -0
- package/dist/types/pipeline.d.ts +157 -0
- package/dist/types/port/client.d.ts +142 -0
- package/dist/types/port/frame.d.ts +195 -0
- package/dist/types/port/serve.d.ts +102 -0
- package/dist/types/project/index.d.ts +34 -0
- package/dist/types/project/markdown.d.ts +28 -0
- package/dist/types/project/openapi.d.ts +102 -0
- package/dist/types/project/tools.d.ts +57 -0
- package/dist/types/project/typescript.d.ts +59 -0
- package/dist/types/public.d.ts +73 -0
- package/dist/types/revision.d.ts +36 -0
- package/dist/types/stream/client.d.ts +104 -0
- package/dist/types/stream/server.d.ts +106 -0
- package/dist/types/stream/sse.d.ts +62 -0
- package/docs/APP-INTEGRATION.md +301 -0
- package/docs/CONTRACT-FORMAT.md +1923 -0
- package/package.json +110 -0
- package/schemas/jaren-contract-port.draft-07.schema.json +241 -0
- package/schemas/jaren-contract-port.schema.json +241 -0
- package/schemas/jaren-contract.draft-07.schema.json +287 -0
- package/schemas/jaren-contract.schema.json +287 -0
- package/src/adapters/fetch.js +109 -0
- package/src/adapters/node.js +238 -0
- package/src/app/binding.js +426 -0
- package/src/app/effect.js +190 -0
- package/src/app/index.js +26 -0
- package/src/app/subscription.js +130 -0
- package/src/bundle.js +168 -0
- package/src/cli.js +264 -0
- package/src/client/http.js +1150 -0
- package/src/client/outcome.js +364 -0
- package/src/compat.js +62 -0
- package/src/compile.js +1162 -0
- package/src/describe.js +109 -0
- package/src/diff.js +610 -0
- package/src/errors.js +236 -0
- package/src/http/dispatch.js +1054 -0
- package/src/http/serve.js +301 -0
- package/src/http/wire.js +469 -0
- package/src/index.js +33 -0
- package/src/ledger.js +225 -0
- package/src/local/index.js +363 -0
- package/src/messages.js +68 -0
- package/src/path.js +471 -0
- package/src/pipeline.js +241 -0
- package/src/port/client.js +518 -0
- package/src/port/frame.js +196 -0
- package/src/port/serve.js +442 -0
- package/src/project/index.js +29 -0
- package/src/project/markdown.js +244 -0
- package/src/project/openapi.js +564 -0
- package/src/project/openapi.jslt.json +149 -0
- package/src/project/tools.js +139 -0
- package/src/project/typescript.js +152 -0
- package/src/project/typescript.jtlt.json +72 -0
- package/src/public.js +206 -0
- package/src/revision.js +90 -0
- package/src/stream/client.js +212 -0
- package/src/stream/server.js +306 -0
- package/src/stream/sse.js +67 -0
package/src/describe.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file `describe()`: a compiled contract as pure JSON — the resolved
|
|
4
|
+
* binding and policy of every operation, with each defaulted value
|
|
5
|
+
* marked in `inferred` so a projection can tell what the author
|
|
6
|
+
* declared from what the compiler filled in. Stable member order, no
|
|
7
|
+
* functions, no schemas (those stay on the compiled operations); this is
|
|
8
|
+
* what a CLI prints and what a golden test compares. `revision` is read
|
|
9
|
+
* synchronously from the memo (`peekRevision`), so it is `null` until
|
|
10
|
+
* someone awaited `contract.revision()` — the well-known responder does
|
|
11
|
+
* exactly that before it renders this document.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { peekRevision } from './revision.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The description of one operation.
|
|
18
|
+
* @typedef {Object} OperationDescription
|
|
19
|
+
* @property {string} id
|
|
20
|
+
* @property {'read' | 'command'} kind
|
|
21
|
+
* @property {string} method
|
|
22
|
+
* @property {string} path - the canonical `{name}` template
|
|
23
|
+
* @property {number} status
|
|
24
|
+
* @property {string} media
|
|
25
|
+
* @property {boolean} opaque
|
|
26
|
+
* @property {Readonly<Record<string, string>>} in - member → location
|
|
27
|
+
* @property {string | null} body - the whole-body member, or null
|
|
28
|
+
* @property {string} task
|
|
29
|
+
* @property {string} idempotency
|
|
30
|
+
* @property {string} cache
|
|
31
|
+
* @property {{ resume: string, heartbeatMs: number, maxPatchBytes: number | null }} [stream]
|
|
32
|
+
* - the resolved stream policy; present exactly on subscribe operations
|
|
33
|
+
* @property {{ http: boolean, status: boolean, media: boolean, in: readonly string[], task: boolean, idempotency: boolean, cache: boolean }} inferred
|
|
34
|
+
* which of the above the compiler defaulted: `http` when the whole
|
|
35
|
+
* binding is the canonical `POST /<id>`, `in` listing the members whose
|
|
36
|
+
* location was not declared
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The description of a contract.
|
|
41
|
+
* @typedef {Object} ContractDescription
|
|
42
|
+
* @property {'0.1'} $contract
|
|
43
|
+
* @property {string | null} id
|
|
44
|
+
* @property {string | null} version
|
|
45
|
+
* @property {readonly string[]} compat
|
|
46
|
+
* @property {string | null} revision - the contract revision (64 lowercase
|
|
47
|
+
* hex; docs/CONTRACT-FORMAT.md §14) when `contract.revision()` has
|
|
48
|
+
* settled, `null` before — `describe()` stays synchronous and never
|
|
49
|
+
* computes it
|
|
50
|
+
* @property {OperationDescription[]} operations - document order
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Describe a compiled contract. Reads the compiled operations for the
|
|
55
|
+
* resolved values and the frozen source document for what was declared.
|
|
56
|
+
* @param {import('./compile.js').Contract} contract
|
|
57
|
+
* @returns {ContractDescription}
|
|
58
|
+
*/
|
|
59
|
+
export function describeContract(contract) {
|
|
60
|
+
const operations = [];
|
|
61
|
+
for (let i = 0; i < contract.ids.length; i++) {
|
|
62
|
+
const id = contract.ids[i];
|
|
63
|
+
const op = contract.operations[id];
|
|
64
|
+
const declared = contract.doc.operations[id];
|
|
65
|
+
const http = declared.http;
|
|
66
|
+
const policy = declared.policy;
|
|
67
|
+
const declaredIn = http !== undefined && http.in !== undefined ? http.in : {};
|
|
68
|
+
const inferredIn = [];
|
|
69
|
+
const members = Object.keys(op.http.in);
|
|
70
|
+
for (let j = 0; j < members.length; j++) {
|
|
71
|
+
const m = members[j];
|
|
72
|
+
const isVariable = op.http.variables.includes(m);
|
|
73
|
+
const isBody = op.http.body === m;
|
|
74
|
+
if (http === undefined || (!isVariable && !isBody && declaredIn[m] === undefined)) inferredIn.push(m);
|
|
75
|
+
}
|
|
76
|
+
operations.push({
|
|
77
|
+
id,
|
|
78
|
+
kind: op.kind,
|
|
79
|
+
method: op.http.method,
|
|
80
|
+
path: op.http.path,
|
|
81
|
+
status: op.http.status,
|
|
82
|
+
media: op.http.media,
|
|
83
|
+
opaque: op.http.opaque,
|
|
84
|
+
in: { ...op.http.in },
|
|
85
|
+
body: op.http.body,
|
|
86
|
+
task: op.policy.task,
|
|
87
|
+
idempotency: op.policy.idempotency,
|
|
88
|
+
cache: op.policy.cache,
|
|
89
|
+
...(op.policy.stream !== null ? { stream: { ...op.policy.stream } } : {}),
|
|
90
|
+
inferred: {
|
|
91
|
+
http: http === undefined,
|
|
92
|
+
status: http === undefined || http.status === undefined,
|
|
93
|
+
media: http === undefined || http.media === undefined,
|
|
94
|
+
in: inferredIn,
|
|
95
|
+
task: policy === undefined || policy.task === undefined,
|
|
96
|
+
idempotency: policy === undefined || policy.idempotency === undefined,
|
|
97
|
+
cache: policy === undefined || policy.cache === undefined,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
$contract: '0.1',
|
|
103
|
+
id: contract.id,
|
|
104
|
+
version: contract.version,
|
|
105
|
+
compat: contract.compat.slice(),
|
|
106
|
+
revision: peekRevision(contract),
|
|
107
|
+
operations,
|
|
108
|
+
};
|
|
109
|
+
}
|