@mdbase-dev/pickle 0.1.0-beta.32 → 0.1.0-beta.34
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/dist/index.d.ts +1 -2
- package/dist/index.js +37 -33
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type ConnectRequestOptions, type MdbaseConnection, type PendingMutation } from "@mdbase-dev/connect";
|
|
1
|
+
import { type CollectionContractDescriptor, type CollectionDescription, type CollectionTypeDescriptor, type JsonObject, type RecordDocument, type ConnectRequestOptions, type MdbaseConnection, type PendingMutation } from "@mdbase-dev/connect";
|
|
3
2
|
export { PICKLE_ACK_RESPONSE_TYPE_DOCUMENT, PICKLE_APPROVAL_RESPONSE_TYPE_DOCUMENT, PICKLE_REQUEST_CONTRACT_DOCUMENT, PICKLE_REQUEST_CONTRACT_DIGEST, PICKLE_TYPE_PACK_PROVISION, PICKLE_REQUEST_TYPE_DOCUMENT } from "./resources.js";
|
|
4
3
|
export declare const PICKLE_REQUEST_CONTRACT = "pickle.request";
|
|
5
4
|
export declare const PICKLE_REQUEST_CONTRACT_VERSION = "1.0.0";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { MDBASE_RECORD_CREATED_CONTRACT } from "@mdbase-dev/connect
|
|
2
|
-
import { ConnectOutcomeError, unwrapConnectOutcome } from "@mdbase-dev/connect";
|
|
1
|
+
import { MDBASE_RECORD_CREATED_CONTRACT, MdbaseConnectError } from "@mdbase-dev/connect";
|
|
3
2
|
import { PICKLE_REQUEST_CONTRACT_DIGEST } from "./resources.js";
|
|
4
3
|
export { PICKLE_ACK_RESPONSE_TYPE_DOCUMENT, PICKLE_APPROVAL_RESPONSE_TYPE_DOCUMENT, PICKLE_REQUEST_CONTRACT_DOCUMENT, PICKLE_REQUEST_CONTRACT_DIGEST, PICKLE_TYPE_PACK_PROVISION, PICKLE_REQUEST_TYPE_DOCUMENT } from "./resources.js";
|
|
5
4
|
export const PICKLE_REQUEST_CONTRACT = "pickle.request";
|
|
@@ -23,11 +22,11 @@ export function resolvePickleContract(description) {
|
|
|
23
22
|
throw new PickleContractError("This collection does not provide the Pickle request contract.");
|
|
24
23
|
}
|
|
25
24
|
const implementations = descriptor.implementations.map((implementation) => {
|
|
26
|
-
const requestType = description.types.find((candidate) => candidate.name === implementation.
|
|
25
|
+
const requestType = description.types.find((candidate) => candidate.name === implementation.typeName);
|
|
27
26
|
if (!requestType)
|
|
28
|
-
throw new PickleContractError(`The Pickle request type ${implementation.
|
|
27
|
+
throw new PickleContractError(`The Pickle request type ${implementation.typeName} is missing from this collection.`);
|
|
29
28
|
return {
|
|
30
|
-
typeName: implementation.
|
|
29
|
+
typeName: implementation.typeName,
|
|
31
30
|
fields: parseFields(implementation.fields),
|
|
32
31
|
binding: implementation.binding,
|
|
33
32
|
requestType
|
|
@@ -48,31 +47,31 @@ export class PickleCollection {
|
|
|
48
47
|
this.connect = connect;
|
|
49
48
|
}
|
|
50
49
|
async describe(options = {}) {
|
|
51
|
-
this.description ??=
|
|
50
|
+
this.description ??= requireOutcome(await this.connect.describe(options));
|
|
52
51
|
this.contract ??= resolvePickleContract(this.description);
|
|
53
52
|
return { collection: this.description, contract: this.contract };
|
|
54
53
|
}
|
|
55
54
|
async list(options = {}) {
|
|
56
55
|
const { collection, contract } = await this.describe(options);
|
|
57
|
-
const requestQuery =
|
|
56
|
+
const requestQuery = requireOutcome(await this.connect.queryAll({
|
|
58
57
|
types: contract.implementations.map(({ typeName }) => typeName),
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
includeBody: true,
|
|
59
|
+
frontmatterMode: "effective"
|
|
61
60
|
}, options));
|
|
62
61
|
const requests = requestQuery.results.map(requireEffectiveFrontmatter);
|
|
63
62
|
const responseTypes = [
|
|
64
63
|
...new Set(requests
|
|
65
64
|
.map((record) => {
|
|
66
65
|
const implementation = implementationForRecord(contract, record);
|
|
67
|
-
return stringField(record.
|
|
66
|
+
return stringField(record.effectiveFrontmatter, role(implementation, "response_type", "response_type"));
|
|
68
67
|
})
|
|
69
68
|
.filter(Boolean))
|
|
70
69
|
];
|
|
71
70
|
const responses = responseTypes.length
|
|
72
|
-
? (
|
|
71
|
+
? (requireOutcome(await this.connect.queryAll({
|
|
73
72
|
types: responseTypes,
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
includeBody: true,
|
|
74
|
+
frontmatterMode: "effective"
|
|
76
75
|
}, options))).results.map(requireEffectiveFrontmatter)
|
|
77
76
|
: [];
|
|
78
77
|
return requests
|
|
@@ -133,13 +132,13 @@ function responseSubmission(outcome) {
|
|
|
133
132
|
: null;
|
|
134
133
|
if (requestId)
|
|
135
134
|
return { kind: "pending", requestId };
|
|
136
|
-
throw new
|
|
135
|
+
throw new MdbaseConnectError(outcome.problem);
|
|
137
136
|
}
|
|
138
137
|
function normalizeRequest(record, responseRecords, description, contract) {
|
|
139
138
|
const implementation = implementationForRecord(contract, record);
|
|
140
|
-
const responseType = stringField(record.
|
|
141
|
-
const linked = responseRecords.filter((candidate) => linkTargets(candidate.
|
|
142
|
-
const status = stringField(record.
|
|
139
|
+
const responseType = stringField(record.effectiveFrontmatter, role(implementation, "response_type", "response_type")) || "pickle_response_approval";
|
|
140
|
+
const linked = responseRecords.filter((candidate) => linkTargets(candidate.effectiveFrontmatter.request, record.path));
|
|
141
|
+
const status = stringField(record.effectiveFrontmatter, role(implementation, "status", "status"));
|
|
143
142
|
const state = status === "cancelled"
|
|
144
143
|
? "cancelled"
|
|
145
144
|
: linked.length === 0
|
|
@@ -149,35 +148,35 @@ function normalizeRequest(record, responseRecords, description, contract) {
|
|
|
149
148
|
: "conflict";
|
|
150
149
|
const response = linked.length === 1 ? normalizeResponse(linked[0]) : undefined;
|
|
151
150
|
return {
|
|
152
|
-
id: stringField(record.
|
|
151
|
+
id: stringField(record.effectiveFrontmatter, role(implementation, "id", "id")) ||
|
|
153
152
|
record.path,
|
|
154
153
|
path: record.path,
|
|
155
|
-
title: stringField(record.
|
|
154
|
+
title: stringField(record.effectiveFrontmatter, role(implementation, "title", "title")) ||
|
|
156
155
|
record.path,
|
|
157
|
-
source: stringField(record.
|
|
156
|
+
source: stringField(record.effectiveFrontmatter, role(implementation, "source", "source")) ||
|
|
158
157
|
"agent",
|
|
159
|
-
message: stringField(record.
|
|
158
|
+
message: stringField(record.effectiveFrontmatter, role(implementation, "message", "message")),
|
|
160
159
|
body: record.body ?? "",
|
|
161
|
-
kind: stringField(record.
|
|
160
|
+
kind: stringField(record.effectiveFrontmatter, role(implementation, "kind", "kind")) ||
|
|
162
161
|
"approval",
|
|
163
|
-
priority: stringField(record.
|
|
162
|
+
priority: stringField(record.effectiveFrontmatter, role(implementation, "priority", "priority")) || "normal",
|
|
164
163
|
status: status || undefined,
|
|
165
164
|
state,
|
|
166
165
|
responseCount: linked.length,
|
|
167
166
|
responseType,
|
|
168
167
|
responseTypeDefinition: description.types.find((candidate) => candidate.name === responseType),
|
|
169
|
-
createdAt: stringField(record.
|
|
170
|
-
dueAt: stringField(record.
|
|
171
|
-
tags: stringList(getField(record.
|
|
172
|
-
links: links(getField(record.
|
|
173
|
-
attachments: attachments(getField(record.
|
|
174
|
-
metadata: asObject(getField(record.
|
|
168
|
+
createdAt: stringField(record.effectiveFrontmatter, role(implementation, "created_at", "created_at")) || undefined,
|
|
169
|
+
dueAt: stringField(record.effectiveFrontmatter, "due_at") || undefined,
|
|
170
|
+
tags: stringList(getField(record.effectiveFrontmatter, role(implementation, "tags", "tags"))),
|
|
171
|
+
links: links(getField(record.effectiveFrontmatter, role(implementation, "links", "links"))),
|
|
172
|
+
attachments: attachments(getField(record.effectiveFrontmatter, role(implementation, "attachment_paths", "attachment_paths"))),
|
|
173
|
+
metadata: asObject(getField(record.effectiveFrontmatter, role(implementation, "metadata", "metadata"))) ?? {},
|
|
175
174
|
response,
|
|
176
|
-
frontmatter: record.
|
|
175
|
+
frontmatter: record.effectiveFrontmatter
|
|
177
176
|
};
|
|
178
177
|
}
|
|
179
178
|
function normalizeResponse(record) {
|
|
180
|
-
const frontmatter = record.
|
|
179
|
+
const frontmatter = record.effectiveFrontmatter;
|
|
181
180
|
return {
|
|
182
181
|
path: record.path,
|
|
183
182
|
type: stringField(frontmatter, "type") || record.types[0] || "pickle_response",
|
|
@@ -188,11 +187,16 @@ function normalizeResponse(record) {
|
|
|
188
187
|
};
|
|
189
188
|
}
|
|
190
189
|
function requireEffectiveFrontmatter(record) {
|
|
191
|
-
if (!record.
|
|
192
|
-
throw new PickleContractError(`Query result ${record.path} omitted
|
|
190
|
+
if (!record.effectiveFrontmatter) {
|
|
191
|
+
throw new PickleContractError(`Query result ${record.path} omitted effectiveFrontmatter.`);
|
|
193
192
|
}
|
|
194
193
|
return record;
|
|
195
194
|
}
|
|
195
|
+
function requireOutcome(outcome) {
|
|
196
|
+
if (!outcome.ok)
|
|
197
|
+
throw new MdbaseConnectError(outcome.problem);
|
|
198
|
+
return outcome.value;
|
|
199
|
+
}
|
|
196
200
|
function parseFields(value) {
|
|
197
201
|
if (!Object.values(value).every((field) => typeof field === "string" && validFieldPath(field)))
|
|
198
202
|
throw new PickleContractError("The Pickle request contract is malformed.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdbase-dev/pickle",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.34",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@mdbase-dev/connect
|
|
26
|
-
"@mdbase-dev/connect": "0.1.0-beta.32"
|
|
25
|
+
"@mdbase-dev/connect": "0.1.0-beta.34"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"typescript": "^7.0.2",
|
|
30
29
|
"vitest": "^4.1.10",
|
|
31
|
-
"@mdbase-dev/connect-dev": "0.1.0-beta.
|
|
30
|
+
"@mdbase-dev/connect-dev": "0.1.0-beta.34",
|
|
31
|
+
"@mdbase-dev/connect-testing": "0.1.0-beta.34"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
|