@sanity-labs/client-fake-for-test 0.9.0 → 0.10.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/README.md +1 -1
- package/dist/index.cjs +28 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +28 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ More patterns — passing the fake to code typed against `SanityClient`, asserti
|
|
|
80
80
|
| Config | `config()` | Returns `{ projectId, dataset, perspective, token?, useProjectHostname }` |
|
|
81
81
|
| Config | `withConfig({ projectId?, dataset?, perspective?, accessControl?, token?, useProjectHostname? })` | Sibling handle into the same multi-dataset registry; `token` binds a registered identity (see the token→identity registry below), `accessControl` rebinds it inline — the two are mutually exclusive; `useProjectHostname: false` mints a global-hosted sibling |
|
|
82
82
|
| Perspectives | `raw` / `published` / `drafts` / release stacks | Per-client default or per-`fetch` override; draft/version layering with `_originalId` projection |
|
|
83
|
-
| HTTP | `request({ url? \| uri? })` | Present **only** when the handle has an acting identity (`accessControl`, or a bound `token`). Serves `/users/me` (host-aware: project-scoped record on the project host, `globalUser` on a global-hosted handle), the configured ACL path, and `/projects/<projectId>/users/<ids>` (project-user records with `id` + `sanityUserId`). Calling it without one throws a guidance error. |
|
|
83
|
+
| HTTP | `request({ url? \| uri? })` | Present **only** when the handle has an acting identity (`accessControl`, or a bound `token`). Serves `/users/me` (host-aware: project-scoped record on the project host, `globalUser` on a global-hosted handle), the configured ACL path, `/projects/<projectId>` (the project's members: `{ id, isRobot? }` rows, one per distinct resolved project user), and `/projects/<projectId>/users/<ids>` (project-user records with `id` + `sanityUserId`). Calling it without one throws a guidance error. |
|
|
84
84
|
|
|
85
85
|
#### Mutation return shapes
|
|
86
86
|
|
package/dist/index.cjs
CHANGED
|
@@ -99,7 +99,18 @@ function serveProjectUsers(args) {
|
|
|
99
99
|
return identity === void 0 ? [] : [toRecord(identity)];
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/;
|
|
102
|
+
const PROJECT_USERS_PATH = /^\/projects\/([^/]+)\/users\/([^/]+)$/, PROJECT_PATH = /^\/projects\/([^/]+)$/;
|
|
103
|
+
function serveProject(args) {
|
|
104
|
+
const ids = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const identity of args.identities)
|
|
106
|
+
ids.add(projectUserOf(identity, args.pathProjectId).id);
|
|
107
|
+
return {
|
|
108
|
+
members: [...ids].map((id) => ({
|
|
109
|
+
id,
|
|
110
|
+
...id.startsWith("p-") ? { isRobot: !0 } : {}
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
}
|
|
103
114
|
function makeRequestImpl(ctx) {
|
|
104
115
|
const { getAccess, projectId, dataset, useProjectHostname, listIdentities } = ctx;
|
|
105
116
|
return async (opts) => {
|
|
@@ -115,8 +126,14 @@ function makeRequestImpl(ctx) {
|
|
|
115
126
|
pathProjectId,
|
|
116
127
|
identities: listIdentities()
|
|
117
128
|
});
|
|
129
|
+
const project = path?.match(PROJECT_PATH), [, membersProjectId] = project ?? [];
|
|
130
|
+
if (membersProjectId !== void 0)
|
|
131
|
+
return serveProject({
|
|
132
|
+
pathProjectId: membersProjectId,
|
|
133
|
+
identities: listIdentities()
|
|
134
|
+
});
|
|
118
135
|
throw fakeError(
|
|
119
|
-
`request(): no handler for path "${path}". With access control configured, the fake serves "/users/me", "${aclPath}", and "/projects/<projectId>/users/<ids>". For any other endpoint, register a stub (client.stub("request", fn)) or intercept the HTTP call with a tool like MSW.`
|
|
136
|
+
`request(): no handler for path "${path}". With access control configured, the fake serves "/users/me", "${aclPath}", "/projects/<projectId>" (members), and "/projects/<projectId>/users/<ids>". For any other endpoint, register a stub (client.stub("request", fn)) or intercept the HTTP call with a tool like MSW.`
|
|
120
137
|
);
|
|
121
138
|
};
|
|
122
139
|
}
|
|
@@ -827,7 +844,7 @@ const ISSUES_URL = "https://github.com/sanity-labs/client-fake-for-test/issues",
|
|
|
827
844
|
},
|
|
828
845
|
request: {
|
|
829
846
|
what: "generic HTTP request hook \u2014 only wired up when the handle has an acting identity",
|
|
830
|
-
workaround: "Create the client with `accessControl`, or bind a registered token (`identities` + `token` / `withConfig({ token })`), to enable request() (it serves /users/me, the ACL path, and /projects/<projectId>/users/<ids>). Or register a stub."
|
|
847
|
+
workaround: "Create the client with `accessControl`, or bind a registered token (`identities` + `token` / `withConfig({ token })`), to enable request() (it serves /users/me, the ACL path, /projects/<projectId>, and /projects/<projectId>/users/<ids>). Or register a stub."
|
|
831
848
|
},
|
|
832
849
|
dryRun: {
|
|
833
850
|
what: "not a method \u2014 did you mean the `{ dryRun }` mutation option?",
|
|
@@ -1016,6 +1033,7 @@ function createTestClient(options = {}) {
|
|
|
1016
1033
|
dataset: defaultDataset,
|
|
1017
1034
|
accessControl: options.accessControl,
|
|
1018
1035
|
perspective: options.perspective ?? "raw",
|
|
1036
|
+
requestTagPrefix: options.requestTagPrefix,
|
|
1019
1037
|
mutationGuard: options.mutationGuard,
|
|
1020
1038
|
token: options.token,
|
|
1021
1039
|
useProjectHostname: options.useProjectHostname ?? !0
|
|
@@ -1078,6 +1096,7 @@ function makeHandle(handleArgs) {
|
|
|
1078
1096
|
dataset,
|
|
1079
1097
|
accessControl,
|
|
1080
1098
|
perspective,
|
|
1099
|
+
requestTagPrefix,
|
|
1081
1100
|
mutationGuard,
|
|
1082
1101
|
token,
|
|
1083
1102
|
useProjectHostname
|
|
@@ -1101,14 +1120,15 @@ function makeHandle(handleArgs) {
|
|
|
1101
1120
|
let s = registry.get(key);
|
|
1102
1121
|
return s === void 0 && (s = createTestStore(), registry.set(key, s)), s;
|
|
1103
1122
|
})(), concurrentEditKey = (id) => registryKey(projectId, dataset) + " " + id, record = (transactionId, mutations, tag) => {
|
|
1123
|
+
const effectiveTag = effectiveRequestTag(tag);
|
|
1104
1124
|
backend.log.push({
|
|
1105
1125
|
transactionId,
|
|
1106
1126
|
projectId,
|
|
1107
1127
|
dataset,
|
|
1108
1128
|
mutations,
|
|
1109
|
-
...
|
|
1129
|
+
...effectiveTag !== void 0 ? { tag: effectiveTag } : {}
|
|
1110
1130
|
});
|
|
1111
|
-
}, writeResult = (documents, results, transactionId, opts) => formatMutationResult(
|
|
1131
|
+
}, effectiveRequestTag = (tag) => requestTagPrefix === void 0 ? tag : tag ? `${requestTagPrefix}.${tag}` : requestTagPrefix, writeResult = (documents, results, transactionId, opts) => formatMutationResult(
|
|
1112
1132
|
documents,
|
|
1113
1133
|
results,
|
|
1114
1134
|
transactionId,
|
|
@@ -1424,6 +1444,7 @@ function makeHandle(handleArgs) {
|
|
|
1424
1444
|
projectId,
|
|
1425
1445
|
dataset,
|
|
1426
1446
|
perspective,
|
|
1447
|
+
...requestTagPrefix !== void 0 ? { requestTagPrefix } : {},
|
|
1427
1448
|
...token !== void 0 ? { token } : {},
|
|
1428
1449
|
useProjectHostname
|
|
1429
1450
|
}),
|
|
@@ -1436,6 +1457,7 @@ function makeHandle(handleArgs) {
|
|
|
1436
1457
|
dataset: config.dataset ?? dataset,
|
|
1437
1458
|
accessControl: rebinds ? config.accessControl : accessControl,
|
|
1438
1459
|
perspective: config.perspective ?? perspective,
|
|
1460
|
+
requestTagPrefix: config.requestTagPrefix ?? requestTagPrefix,
|
|
1439
1461
|
mutationGuard,
|
|
1440
1462
|
token: rebinds ? config.token : token,
|
|
1441
1463
|
useProjectHostname: config.useProjectHostname ?? useProjectHostname
|
|
@@ -1473,7 +1495,7 @@ function makeHandle(handleArgs) {
|
|
|
1473
1495
|
return wrapWithGuards(client, {
|
|
1474
1496
|
getStub: (name) => backend.stubs.get(name),
|
|
1475
1497
|
onCall: (method, args) => {
|
|
1476
|
-
const rec = { method, args, projectId, dataset }, tag = tagFromArgs(method, args);
|
|
1498
|
+
const rec = { method, args, projectId, dataset }, tag = OPTIONS_ARG_POSITION[method] === void 0 ? void 0 : effectiveRequestTag(tagFromArgs(method, args));
|
|
1477
1499
|
return tag !== void 0 && (rec.tag = tag), backend.calls.push(rec), (outcome) => {
|
|
1478
1500
|
"error" in outcome ? rec.error = outcome.error : rec.result = outcome.result;
|
|
1479
1501
|
};
|