@hyperframes/share 0.9.28-alpha.1 → 0.9.28

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.
Files changed (56) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +1 -58
  3. package/dist/index.d.mts +0 -1
  4. package/dist/projectLock.d.mts +2 -2
  5. package/dist/projectSnapshot.d.mts +1 -3
  6. package/dist/reviewClient.d.mts +16 -13
  7. package/dist/reviewExport.d.mts +1 -11
  8. package/dist/reviewUpload.d.mts +0 -2
  9. package/package.json +1 -1
  10. package/scripts/copy-types.mjs +0 -3
  11. package/src/index.mjs +0 -6
  12. package/src/projectLock.mjs +2 -9
  13. package/src/projectSnapshot.mjs +6 -22
  14. package/src/reviewClient.mjs +83 -48
  15. package/src/reviewExport.mjs +41 -156
  16. package/src/reviewUpload.mjs +16 -18
  17. package/src/reviewVersionSentences.mjs +1 -2
  18. package/dist/shareSources.d.mts +0 -24
  19. package/dist/sourceIgnore.d.mts +0 -3
  20. package/dist/sources/adapterTypes.d.ts +0 -39
  21. package/dist/sources/api.d.mts +0 -29
  22. package/dist/sources/capture.d.mts +0 -24
  23. package/dist/sources/contract.d.mts +0 -2
  24. package/dist/sources/errors.d.mts +0 -24
  25. package/dist/sources/limits.d.mts +0 -12
  26. package/dist/sources/manifest.d.mts +0 -23
  27. package/dist/sources/pathPolicy.d.mts +0 -25
  28. package/dist/sources/projectState.d.mts +0 -9
  29. package/dist/sources/store.d.mts +0 -3
  30. package/dist/sources/transfer.d.mts +0 -45
  31. package/dist/sources/types.d.ts +0 -353
  32. package/dist/sources/unicode.d.mts +0 -15
  33. package/dist/sources/upload.d.mts +0 -9
  34. package/dist/sources/uploadFiles.d.mts +0 -31
  35. package/dist/sources/wire.d.mts +0 -21
  36. package/src/shareSources.mjs +0 -236
  37. package/src/sourceIgnore.mjs +0 -69
  38. package/src/sources/adapterTypes.d.ts +0 -39
  39. package/src/sources/api.mjs +0 -114
  40. package/src/sources/capture.mjs +0 -264
  41. package/src/sources/contract/LICENSE-Unicode.txt +0 -39
  42. package/src/sources/contract/path-policy.json +0 -311
  43. package/src/sources/contract/unicode-15.1.0.json +0 -6179
  44. package/src/sources/contract.mjs +0 -13
  45. package/src/sources/errors.mjs +0 -77
  46. package/src/sources/limits.mjs +0 -48
  47. package/src/sources/manifest.mjs +0 -154
  48. package/src/sources/pathPolicy.mjs +0 -197
  49. package/src/sources/projectState.mjs +0 -59
  50. package/src/sources/store.mjs +0 -82
  51. package/src/sources/transfer.mjs +0 -196
  52. package/src/sources/types.d.ts +0 -353
  53. package/src/sources/unicode.mjs +0 -163
  54. package/src/sources/upload.mjs +0 -201
  55. package/src/sources/uploadFiles.mjs +0 -263
  56. package/src/sources/wire.mjs +0 -205
@@ -1,205 +0,0 @@
1
- // @ts-check
2
- // Parse and validate sync API responses at the transport boundary.
3
- import { ManifestInvalid, parseStoredManifest } from "./manifest.mjs";
4
- import { SyncApiError } from "./errors.mjs";
5
-
6
- /** @typedef {import("./types.js").SyncLimitsRead} SyncLimitsRead
7
- * @typedef {import("./types.js").Composition} Composition @typedef {import("./types.js").Snapshot} Snapshot
8
- * @typedef {import("./types.js").UploadReceipt} UploadReceipt @typedef {import("./types.js").BeginResult} BeginResult
9
- * @typedef {import("./types.js").FileGrant} FileGrant @typedef {import("./types.js").DownloadBatch} DownloadBatch */
10
-
11
- /** @param {string} field */
12
- const malformed = (field) =>
13
- new SyncApiError("malformed", { detail: `missing or mistyped ${field}` });
14
-
15
- /** @param {unknown} value @param {string} field @returns {Record<string, unknown>} */
16
- export function objectOf(value, field) {
17
- if (typeof value !== "object" || value === null || Array.isArray(value)) throw malformed(field);
18
- return /** @type {Record<string, unknown>} */ (value);
19
- }
20
- /** @param {Record<string, unknown>} o @param {string} key @returns {string} */
21
- const str = (o, key) => {
22
- const value = o[key];
23
- if (typeof value !== "string") throw malformed(key);
24
- return value;
25
- };
26
- /** Absent (the server drops nulls) reads as null. @param {Record<string, unknown>} o @param {string} key */
27
- const optStr = (o, key) => (o[key] === undefined || o[key] === null ? null : str(o, key));
28
- /** @param {Record<string, unknown>} o @param {string} key @returns {number} */
29
- const int = (o, key) => {
30
- const value = o[key];
31
- if (typeof value !== "number" || !Number.isSafeInteger(value)) throw malformed(key);
32
- return value;
33
- };
34
- /** @param {Record<string, unknown>} o @param {string} key @returns {unknown[]} */
35
- const list = (o, key) => {
36
- const value = o[key] ?? [];
37
- if (!Array.isArray(value)) throw malformed(key);
38
- return value;
39
- };
40
- /** @param {Record<string, unknown>} o @param {string} key @returns {Record<string, string>} */
41
- const headers = (o, key) => {
42
- const value = objectOf(o[key] ?? {}, key);
43
- return Object.fromEntries(Object.keys(value).map((name) => [name, str(value, name)]));
44
- };
45
- /** @template {string} T @param {Record<string, unknown>} o @param {string} key @param {readonly T[]} allowed
46
- * @returns {T} */
47
- const oneOf = (o, key, allowed) => {
48
- const value = str(o, key);
49
- if (!allowed.includes(/** @type {T} */ (value))) throw malformed(key);
50
- return /** @type {T} */ (value);
51
- };
52
-
53
- /** @param {unknown} raw @returns {Composition} */
54
- export function compositionOf(raw) {
55
- const o = objectOf(raw, "composition");
56
- return {
57
- id: str(o, "id"),
58
- spaceId: str(o, "space_id"),
59
- title: str(o, "title"),
60
- createdBy: str(o, "created_by"),
61
- latestSnapshotId: optStr(o, "latest_snapshot_id"),
62
- createdAt: str(o, "created_at"),
63
- updatedAt: str(o, "updated_at"),
64
- };
65
- }
66
-
67
- /** The snapshot's manifest, trusted only when its canonical bytes hash to the snapshot's manifest_sha256.
68
- * @param {unknown} raw @param {string} sha256 */
69
- function snapshotManifestOf(raw, sha256) {
70
- const o = objectOf(raw, "manifest");
71
- try {
72
- const manifest = parseStoredManifest(o.document);
73
- if (manifest.sha256 !== sha256) throw malformed("manifest.document (sha256)");
74
- return manifest;
75
- } catch (error) {
76
- if (error instanceof ManifestInvalid) throw malformed(`manifest.document (${error.code})`);
77
- throw error;
78
- }
79
- }
80
-
81
- /** @param {unknown} raw @returns {Snapshot} */
82
- export function snapshotOf(raw) {
83
- const o = objectOf(raw, "snapshot");
84
- const manifestSha256 = str(o, "manifest_sha256");
85
- const state = optStr(o, "conflict_state");
86
- if (state !== null && !["open", "resolved", "discarded"].includes(state))
87
- throw malformed("conflict_state");
88
- return {
89
- id: str(o, "id"),
90
- compositionId: str(o, "composition_id"),
91
- baseSnapshotId: optStr(o, "base_snapshot_id"),
92
- publicationOutcome: oneOf(
93
- o,
94
- "publication_outcome",
95
- /** @type {const} */ (["published", "conflict_saved"]),
96
- ),
97
- conflictedWithSnapshotId: optStr(o, "conflicted_with_snapshot_id"),
98
- conflictState: /** @type {Snapshot["conflictState"]} */ (state),
99
- resolvedBySnapshotId: optStr(o, "resolved_by_snapshot_id"),
100
- createdBy: str(o, "created_by"),
101
- createdByName: optStr(o, "created_by_name"),
102
- clientType: str(o, "client_type"),
103
- summary: optStr(o, "summary"),
104
- summarySource: str(o, "summary_source"),
105
- manifestSha256,
106
- createdAt: str(o, "created_at"),
107
- manifest: o.manifest === undefined ? null : snapshotManifestOf(o.manifest, manifestSha256),
108
- };
109
- }
110
-
111
- const UPLOAD_STATUSES = /** @type {const} */ ([
112
- "pending",
113
- "verifying",
114
- "completed",
115
- "failed",
116
- "expired",
117
- ]);
118
-
119
- /** @param {unknown} raw @returns {UploadReceipt} */
120
- export function uploadOf(raw) {
121
- const o = objectOf(raw, "upload");
122
- const result = o.result === undefined || o.result === null ? null : objectOf(o.result, "result");
123
- return {
124
- uploadId: str(o, "upload_id"),
125
- compositionId: str(o, "composition_id"),
126
- snapshotId: str(o, "snapshot_id"),
127
- status: oneOf(o, "status", UPLOAD_STATUSES),
128
- errorCode: optStr(o, "error_code"),
129
- baseSnapshotId: optStr(o, "base_snapshot_id"),
130
- resolvesConflictSnapshotIds: list(o, "resolves_conflict_snapshot_ids").map((id) => {
131
- if (typeof id !== "string") throw malformed("resolves_conflict_snapshot_ids");
132
- return id;
133
- }),
134
- manifestSha256: str(o, "manifest_sha256"),
135
- uploadDeadline: str(o, "upload_deadline"),
136
- verificationDeadline: optStr(o, "verification_deadline"),
137
- completedAt: optStr(o, "completed_at"),
138
- result: result && {
139
- snapshotId: str(result, "snapshot_id"),
140
- publicationOutcome: oneOf(
141
- result,
142
- "publication_outcome",
143
- /** @type {const} */ (["published", "conflict_saved"]),
144
- ),
145
- conflictedWithSnapshotId: optStr(result, "conflicted_with_snapshot_id"),
146
- },
147
- };
148
- }
149
-
150
- /** @param {unknown} raw @param {string} field */
151
- const blobsOf = (raw, field) =>
152
- list(objectOf(raw, field), field).map((item) => {
153
- const blob = objectOf(item, field);
154
- return { sha256: str(blob, "sha256"), size: int(blob, "size") };
155
- });
156
-
157
- /** @param {unknown} raw @param {boolean} created @returns {BeginResult} */
158
- export const beginOf = (raw, created) => ({
159
- ...uploadOf(raw),
160
- present: blobsOf(raw, "present"),
161
- needed: blobsOf(raw, "needed"),
162
- created,
163
- });
164
-
165
- /** @param {unknown} raw @returns {FileGrant[]} */
166
- export const grantsOf = (raw) =>
167
- list(objectOf(raw, "grants"), "files").map((item) => {
168
- const o = objectOf(item, "files");
169
- return {
170
- sha256: str(o, "sha256"),
171
- size: int(o, "size"),
172
- expiresAt: str(o, "expires_at"),
173
- url: optStr(o, "url"),
174
- headers: headers(o, "headers"),
175
- multipartUploadId: optStr(o, "multipart_upload_id"),
176
- parts: list(o, "parts").map((part) => {
177
- const p = objectOf(part, "parts");
178
- return {
179
- partNumber: int(p, "part_number"),
180
- length: int(p, "length"),
181
- url: str(p, "url"),
182
- headers: headers(p, "headers"),
183
- };
184
- }),
185
- };
186
- });
187
-
188
- /** @param {unknown} raw @returns {Extract<SyncLimitsRead, { at: "read" }>} */
189
- export function syncLimitsOf(raw) {
190
- const o = objectOf(raw, "limits answer");
191
- const limits = objectOf(o.limits, "limits");
192
- if (typeof o.sync_allowed !== "boolean") throw malformed("sync_allowed");
193
- return {
194
- at: "read",
195
- syncAllowed: o.sync_allowed,
196
- maxCompositions: int(limits, "max_compositions"),
197
- compositions: int(objectOf(o.usage, "usage"), "compositions"),
198
- push: {
199
- maxFiles: int(limits, "max_files"),
200
- maxFileBytes: int(limits, "max_file_bytes"),
201
- maxProjectBytes: int(limits, "max_project_bytes"),
202
- maxManifestBytes: int(limits, "max_manifest_bytes"),
203
- },
204
- };
205
- }