gm-pantry 0.3.1 → 0.4.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/dist/builder.d.ts CHANGED
@@ -14,6 +14,12 @@ export interface NewVersion {
14
14
  version?: string;
15
15
  notes?: string;
16
16
  released?: string;
17
+ /** What is inside the archive (paths relative to its root) and its README text, if any. */
18
+ contents?: {
19
+ path: string;
20
+ size: number;
21
+ }[];
22
+ readme?: string;
17
23
  format?: string;
18
24
  file: {
19
25
  url: string;
package/dist/builder.js CHANGED
@@ -18,6 +18,10 @@ export function addVersion(repo, v) {
18
18
  for (const old of game.versions ?? []) {
19
19
  if (old.file?.url === v.file.url) {
20
20
  old.file = { ...old.file, sha256: v.file.sha256, size: v.file.size };
21
+ if (v.contents)
22
+ old.contents = v.contents;
23
+ if (v.readme)
24
+ old.readme = v.readme;
21
25
  return game;
22
26
  }
23
27
  }
@@ -40,8 +44,8 @@ export function addVersion(repo, v) {
40
44
  ;
41
45
  else if (taken.has(label))
42
46
  throw new Error(`game ${id} already has a version ${label}`);
43
- const { notes, released, format, file } = v;
44
- game.versions.unshift({ version: label, file, ...(format && { format }), ...(notes && { notes }), ...(released && { released }) });
47
+ const { notes, released, format, file, contents, readme } = v;
48
+ game.versions.unshift({ version: label, file, ...(format && { format }), ...(notes && { notes }), ...(contents && { contents }), ...(readme && { readme }), ...(released && { released }) });
45
49
  return game;
46
50
  }
47
51
  /** Adds an archive by its url, deriving the game id and title from the file name. */
package/dist/parse.d.ts CHANGED
@@ -13,6 +13,9 @@ export declare const LIMITS: {
13
13
  readonly metaText: 2000;
14
14
  readonly author: 120;
15
15
  readonly notes: 2000;
16
+ readonly contents: 2000;
17
+ readonly contentPath: 260;
18
+ readonly readme: 20000;
16
19
  readonly tags: 20;
17
20
  readonly tag: 40;
18
21
  readonly screenshots: 20;
package/dist/parse.js CHANGED
@@ -14,6 +14,9 @@ export const LIMITS = {
14
14
  metaText: 2000,
15
15
  author: 120,
16
16
  notes: 2000,
17
+ contents: 2000,
18
+ contentPath: 260,
19
+ readme: 20000,
17
20
  tags: 20,
18
21
  tag: 40,
19
22
  screenshots: 20,
@@ -202,12 +205,34 @@ function parseVersion(v, path, baseUrl, warn) {
202
205
  version.notes = notes;
203
206
  else if (v.notes !== undefined)
204
207
  warn(`${path}.notes`, "dropped");
208
+ const contents = parseContents(v.contents);
209
+ if (contents)
210
+ version.contents = contents;
211
+ else if (v.contents !== undefined)
212
+ warn(`${path}.contents`, "dropped: not a list of {path, size} of at most 2000 entries");
213
+ if (typeof v.readme === "string" && v.readme.trim() !== "" && v.readme.length <= LIMITS.readme)
214
+ version.readme = v.readme;
215
+ else if (v.readme !== undefined)
216
+ warn(`${path}.readme`, "dropped");
205
217
  if (validDate(v.released))
206
218
  version.released = v.released;
207
219
  else if (v.released !== undefined)
208
220
  warn(`${path}.released`, "dropped: not an ISO-8601 date");
209
221
  return version;
210
222
  }
223
+ function parseContents(c) {
224
+ if (!Array.isArray(c) || c.length === 0 || c.length > LIMITS.contents)
225
+ return undefined;
226
+ const out = [];
227
+ for (const e of c) {
228
+ if (!isObject(e) || typeof e.path !== "string" || e.path === "" || e.path.length > LIMITS.contentPath)
229
+ return undefined;
230
+ if (!Number.isSafeInteger(e.size) || e.size < 0)
231
+ return undefined;
232
+ out.push({ path: e.path, size: e.size });
233
+ }
234
+ return out;
235
+ }
211
236
  function parseWork(w) {
212
237
  if (!isObject(w))
213
238
  return undefined;
package/dist/types.d.ts CHANGED
@@ -13,6 +13,13 @@ export interface Version {
13
13
  /** Claimed hash of the normalised game payload; a hint, consumers recompute. */
14
14
  build?: string;
15
15
  notes?: string;
16
+ /** What is inside the archive, so a consumer can tell what it holds without downloading it. Advisory. */
17
+ contents?: {
18
+ path: string;
19
+ size: number;
20
+ }[];
21
+ /** The archive's README text, so it can be shown without downloading the archive. Advisory. */
22
+ readme?: string;
16
23
  /** YYYY-MM-DD, or a full ISO-8601 timestamp. */
17
24
  released?: string;
18
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-pantry",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Game repositories: static directories of game archives with a repo.json, plus a parser, validator and CLI.",
5
5
  "keywords": [
6
6
  "gamemaker",