@fastly/compute-js-static-publish 7.0.0-beta.1 → 7.0.0-beta.3

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 (84) hide show
  1. package/README.md +11 -3
  2. package/README.short.md +11 -3
  3. package/build/cli/commands/manage/clean.d.ts +2 -0
  4. package/build/cli/commands/manage/clean.d.ts.map +1 -0
  5. package/build/cli/commands/manage/clean.js +277 -0
  6. package/build/cli/commands/manage/collections/delete.d.ts +2 -0
  7. package/build/cli/commands/manage/collections/delete.d.ts.map +1 -0
  8. package/build/cli/commands/manage/collections/delete.js +180 -0
  9. package/build/cli/commands/manage/collections/index.d.ts.map +1 -0
  10. package/build/cli/commands/manage/collections/index.js +63 -0
  11. package/build/cli/commands/manage/collections/list.d.ts +2 -0
  12. package/build/cli/commands/manage/collections/list.d.ts.map +1 -0
  13. package/build/cli/commands/manage/collections/list.js +191 -0
  14. package/build/cli/commands/manage/collections/promote.d.ts +2 -0
  15. package/build/cli/commands/manage/collections/promote.d.ts.map +1 -0
  16. package/build/cli/commands/manage/collections/promote.js +247 -0
  17. package/build/cli/commands/manage/collections/update-expiration.d.ts +2 -0
  18. package/build/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
  19. package/build/cli/commands/manage/collections/update-expiration.js +215 -0
  20. package/build/cli/commands/manage/index.d.ts.map +1 -0
  21. package/build/cli/commands/{index.js → manage/index.js} +36 -34
  22. package/build/cli/commands/manage/publish-content.d.ts +2 -0
  23. package/build/cli/commands/manage/publish-content.d.ts.map +1 -0
  24. package/build/cli/commands/{publish-content.js → manage/publish-content.js} +186 -85
  25. package/build/cli/commands/{init-app.d.ts → scaffold/index.d.ts} +2 -2
  26. package/build/cli/commands/scaffold/index.d.ts.map +1 -0
  27. package/build/cli/commands/{init-app.js → scaffold/index.js} +80 -31
  28. package/build/cli/index.js +11 -3
  29. package/build/cli/util/api-token.d.ts.map +1 -0
  30. package/build/cli/{fastly-api → util}/api-token.js +8 -2
  31. package/build/cli/util/args.d.ts +16 -2
  32. package/build/cli/util/args.d.ts.map +1 -1
  33. package/build/cli/util/args.js +32 -6
  34. package/build/cli/util/config.d.ts.map +1 -1
  35. package/build/cli/util/config.js +19 -19
  36. package/build/cli/util/fastly-toml.d.ts +2 -0
  37. package/build/cli/util/fastly-toml.d.ts.map +1 -0
  38. package/build/cli/util/fastly-toml.js +15 -0
  39. package/build/cli/util/kv-store-items.d.ts +3 -2
  40. package/build/cli/util/kv-store-items.d.ts.map +1 -1
  41. package/build/cli/util/kv-store-items.js +7 -13
  42. package/build/cli/util/kv-store-local-server.d.ts +8 -0
  43. package/build/cli/util/kv-store-local-server.d.ts.map +1 -1
  44. package/build/cli/util/kv-store-local-server.js +76 -0
  45. package/build/cli/{fastly-api → util}/kv-store.d.ts +6 -6
  46. package/build/cli/util/kv-store.d.ts.map +1 -0
  47. package/build/cli/{fastly-api → util}/kv-store.js +4 -4
  48. package/build/cli/util/node.d.ts +2 -0
  49. package/build/cli/util/node.d.ts.map +1 -0
  50. package/build/cli/util/node.js +10 -0
  51. package/build/models/config/publish-content-config.d.ts +0 -2
  52. package/build/models/config/publish-content-config.d.ts.map +1 -1
  53. package/build/models/config/static-publish-rc.d.ts +1 -0
  54. package/build/models/config/static-publish-rc.d.ts.map +1 -1
  55. package/build/models/server/index.d.ts +5 -0
  56. package/build/models/server/index.d.ts.map +1 -0
  57. package/build/models/server/index.js +1 -0
  58. package/build/models/time/index.d.ts +8 -0
  59. package/build/models/time/index.d.ts.map +1 -0
  60. package/build/models/time/index.js +54 -0
  61. package/build/server/publisher-server/index.d.ts +2 -0
  62. package/build/server/publisher-server/index.d.ts.map +1 -1
  63. package/build/server/publisher-server/index.js +34 -3
  64. package/package.json +3 -2
  65. package/build/cli/commands/clean.d.ts +0 -2
  66. package/build/cli/commands/clean.d.ts.map +0 -1
  67. package/build/cli/commands/clean.js +0 -121
  68. package/build/cli/commands/collections/delete.d.ts +0 -2
  69. package/build/cli/commands/collections/delete.d.ts.map +0 -1
  70. package/build/cli/commands/collections/delete.js +0 -88
  71. package/build/cli/commands/collections/index.d.ts.map +0 -1
  72. package/build/cli/commands/collections/index.js +0 -52
  73. package/build/cli/commands/collections/list.d.ts +0 -2
  74. package/build/cli/commands/collections/list.d.ts.map +0 -1
  75. package/build/cli/commands/collections/list.js +0 -62
  76. package/build/cli/commands/index.d.ts.map +0 -1
  77. package/build/cli/commands/init-app.d.ts.map +0 -1
  78. package/build/cli/commands/publish-content.d.ts +0 -2
  79. package/build/cli/commands/publish-content.d.ts.map +0 -1
  80. package/build/cli/fastly-api/api-token.d.ts.map +0 -1
  81. package/build/cli/fastly-api/kv-store.d.ts.map +0 -1
  82. /package/build/cli/commands/{collections → manage/collections}/index.d.ts +0 -0
  83. /package/build/cli/commands/{index.d.ts → manage/index.d.ts} +0 -0
  84. /package/build/cli/{fastly-api → util}/api-token.d.ts +0 -0
@@ -9,9 +9,48 @@
9
9
  import * as child_process from 'node:child_process';
10
10
  import * as path from 'node:path';
11
11
  import * as fs from 'node:fs';
12
- import commandLineArgs from 'command-line-args';
13
- import { dotRelative, rootRelative } from '../util/files.js';
14
- import { findComputeJsStaticPublisherVersion } from '../util/package.js';
12
+ import { dotRelative, rootRelative } from '../../util/files.js';
13
+ import { findComputeJsStaticPublisherVersion } from '../../util/package.js';
14
+ import { parseCommandLine } from "../../util/args.js";
15
+ function help() {
16
+ console.log(`\
17
+
18
+ Usage:
19
+ npx @fastly/compute-js-static-publish [options]
20
+
21
+ Description:
22
+ Scaffold a new Compute app configured for static publishing.
23
+
24
+ Note: If run inside a scaffolded project, this tool will automatically enter project
25
+ management mode.
26
+
27
+ Options:
28
+ --kv-store-name <name> (required) KV Store name for content storage
29
+ --root-dir <path> (required) Path to static content (e.g., ./public)
30
+ -o, --output <dir> Output directory for Compute app (default: ./compute-js)
31
+ --static-publisher-working-dir <dir> Working directory for build artifacts (default: <output>/static-publisher)
32
+ --publish-id <id> Advanced. Prefix for KV keys (default: "default")
33
+ (default: ./compute-js/static-publisher)
34
+
35
+ Compute Service Metadata:
36
+ --name <name> App name (for fastly.toml)
37
+ --description <text> App description (for fastly.toml)
38
+ --author <name/email> App author (for fastly.toml)
39
+ --service-id <id> (optional) Fastly service ID
40
+
41
+ Server Config:
42
+ --public-dir <path> Base dir for content (default: root-dir)
43
+ --static-dir <path>,<path...> Directory served with long TTL (can repeat)
44
+ --spa <file> SPA fallback file (e.g., /index.html)
45
+ --not-found-page <file> 404 fallback file (e.g., /404.html)
46
+ --auto-index <name>,<name...> Index filename (e.g., index.html,index.htm)
47
+ --auto-ext <ext>,<ext...> Automatic extensions (e.g., .html,.htm)
48
+
49
+ Other:
50
+ --verbose Enable verbose output
51
+ -h, --help Show help
52
+ `);
53
+ }
15
54
  const defaultOptions = {
16
55
  outputDir: undefined,
17
56
  rootDir: undefined,
@@ -29,7 +68,7 @@ const defaultOptions = {
29
68
  publishId: undefined,
30
69
  kvStoreName: undefined,
31
70
  };
32
- function buildOptions(packageJson, commandLineValues) {
71
+ function buildOptions(packageJson, commandLineOptions) {
33
72
  // Applied in this order for proper overriding
34
73
  // 1. defaults
35
74
  // 2. package.json
@@ -46,7 +85,7 @@ function buildOptions(packageJson, commandLineValues) {
46
85
  }
47
86
  {
48
87
  let outputDir;
49
- const outputDirValue = commandLineValues['output'];
88
+ const outputDirValue = commandLineOptions['output'];
50
89
  if (outputDirValue == null || typeof outputDirValue === 'string') {
51
90
  outputDir = outputDirValue;
52
91
  }
@@ -56,7 +95,7 @@ function buildOptions(packageJson, commandLineValues) {
56
95
  }
57
96
  {
58
97
  let rootDir;
59
- const rootDirValue = commandLineValues['root-dir'];
98
+ const rootDirValue = commandLineOptions['root-dir'];
60
99
  if (rootDirValue == null || typeof rootDirValue === 'string') {
61
100
  rootDir = rootDirValue;
62
101
  }
@@ -66,7 +105,7 @@ function buildOptions(packageJson, commandLineValues) {
66
105
  }
67
106
  {
68
107
  let publicDir;
69
- const publicDirValue = commandLineValues['public-dir'];
108
+ const publicDirValue = commandLineOptions['public-dir'];
70
109
  if (publicDirValue == null || typeof publicDirValue === 'string') {
71
110
  publicDir = publicDirValue;
72
111
  }
@@ -76,7 +115,7 @@ function buildOptions(packageJson, commandLineValues) {
76
115
  }
77
116
  {
78
117
  let staticDirs;
79
- const staticDirsValue = commandLineValues['static-dir'];
118
+ const staticDirsValue = commandLineOptions['static-dir'];
80
119
  const asArray = Array.isArray(staticDirsValue) ? staticDirsValue : [staticDirsValue];
81
120
  if (asArray.every((x) => typeof x === 'string')) {
82
121
  staticDirs = asArray;
@@ -87,7 +126,7 @@ function buildOptions(packageJson, commandLineValues) {
87
126
  }
88
127
  {
89
128
  let staticPublisherWorkingDir;
90
- const staticPublisherWorkingDirValue = commandLineValues['static-publisher-working-dir'];
129
+ const staticPublisherWorkingDirValue = commandLineOptions['static-publisher-working-dir'];
91
130
  if (staticPublisherWorkingDirValue == null || typeof staticPublisherWorkingDirValue === 'string') {
92
131
  staticPublisherWorkingDir = staticPublisherWorkingDirValue;
93
132
  }
@@ -97,7 +136,7 @@ function buildOptions(packageJson, commandLineValues) {
97
136
  }
98
137
  {
99
138
  let spa;
100
- const spaValue = commandLineValues['spa'];
139
+ const spaValue = commandLineOptions['spa'];
101
140
  if (spaValue === null) {
102
141
  // If 'spa' is provided with a null value, then the flag was provided
103
142
  // with no value. Assumed to be './index.html' relative to the public directory.
@@ -113,7 +152,7 @@ function buildOptions(packageJson, commandLineValues) {
113
152
  }
114
153
  {
115
154
  let notFoundPage;
116
- const notFoundPageValue = commandLineValues['not-found-page'];
155
+ const notFoundPageValue = commandLineOptions['not-found-page'];
117
156
  if (notFoundPageValue === null) {
118
157
  // If 'spa' is provided with a null value, then the flag was provided
119
158
  // with no value. Assumed to be './404.html' relative to the public directory.
@@ -129,7 +168,7 @@ function buildOptions(packageJson, commandLineValues) {
129
168
  }
130
169
  {
131
170
  let autoIndex;
132
- const autoIndexValue = commandLineValues['auto-index'];
171
+ const autoIndexValue = commandLineOptions['auto-index'];
133
172
  const asArray = Array.isArray(autoIndexValue) ? autoIndexValue : [autoIndexValue];
134
173
  if (asArray.every((x) => typeof x === 'string')) {
135
174
  autoIndex = asArray.reduce((acc, entry) => {
@@ -149,7 +188,7 @@ function buildOptions(packageJson, commandLineValues) {
149
188
  }
150
189
  {
151
190
  let autoExt = [];
152
- const autoExtValue = commandLineValues['auto-ext'];
191
+ const autoExtValue = commandLineOptions['auto-ext'];
153
192
  const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
154
193
  if (asArray.every((x) => typeof x === 'string')) {
155
194
  autoExt = asArray.reduce((acc, entry) => {
@@ -170,7 +209,7 @@ function buildOptions(packageJson, commandLineValues) {
170
209
  }
171
210
  {
172
211
  let name;
173
- const nameValue = commandLineValues['name'];
212
+ const nameValue = commandLineOptions['name'];
174
213
  if (nameValue == null || typeof nameValue === 'string') {
175
214
  name = nameValue;
176
215
  }
@@ -180,7 +219,7 @@ function buildOptions(packageJson, commandLineValues) {
180
219
  }
181
220
  {
182
221
  let author;
183
- const authorValue = commandLineValues['author'];
222
+ const authorValue = commandLineOptions['author'];
184
223
  if (authorValue == null || typeof authorValue === 'string') {
185
224
  author = authorValue;
186
225
  }
@@ -190,7 +229,7 @@ function buildOptions(packageJson, commandLineValues) {
190
229
  }
191
230
  {
192
231
  let description;
193
- const descriptionValue = commandLineValues['description'];
232
+ const descriptionValue = commandLineOptions['description'];
194
233
  if (descriptionValue == null || typeof descriptionValue === 'string') {
195
234
  description = descriptionValue;
196
235
  }
@@ -200,7 +239,7 @@ function buildOptions(packageJson, commandLineValues) {
200
239
  }
201
240
  {
202
241
  let serviceId;
203
- const serviceIdValue = commandLineValues['service-id'];
242
+ const serviceIdValue = commandLineOptions['service-id'];
204
243
  if (serviceIdValue == null || typeof serviceIdValue === 'string') {
205
244
  serviceId = serviceIdValue;
206
245
  }
@@ -210,7 +249,7 @@ function buildOptions(packageJson, commandLineValues) {
210
249
  }
211
250
  {
212
251
  let publishId;
213
- const publishIdValue = commandLineValues['publish-id'];
252
+ const publishIdValue = commandLineOptions['publish-id'];
214
253
  if (publishIdValue == null || typeof publishIdValue === 'string') {
215
254
  publishId = publishIdValue;
216
255
  }
@@ -220,7 +259,7 @@ function buildOptions(packageJson, commandLineValues) {
220
259
  }
221
260
  {
222
261
  let kvStoreName;
223
- const kvStoreNameValue = commandLineValues['kv-store-name'];
262
+ const kvStoreNameValue = commandLineOptions['kv-store-name'];
224
263
  if (kvStoreNameValue == null || typeof kvStoreNameValue === 'string') {
225
264
  kvStoreName = kvStoreNameValue;
226
265
  }
@@ -238,7 +277,7 @@ function processPublicDirToken(filepath, publicDir) {
238
277
  const processedPath = '.' + filepath.slice(PUBLIC_DIR_TOKEN.length);
239
278
  return path.resolve(publicDir, processedPath);
240
279
  }
241
- export async function action(argv) {
280
+ export async function action(actionArgs) {
242
281
  const optionDefinitions = [
243
282
  { name: 'verbose', type: Boolean },
244
283
  // Required. The name of a Fastly KV Store to hold the content assets.
@@ -295,7 +334,16 @@ export async function action(argv) {
295
334
  // http://example.com/about is requested, we can respond with http://example.com/about.html
296
335
  { name: 'auto-ext', type: String, multiple: true, },
297
336
  ];
298
- const commandLineValues = commandLineArgs(optionDefinitions, { argv });
337
+ const parsed = parseCommandLine(actionArgs, optionDefinitions);
338
+ if (parsed.needHelp) {
339
+ if (parsed.error != null) {
340
+ console.error(String(parsed.error));
341
+ console.error();
342
+ process.exitCode = 1;
343
+ }
344
+ help();
345
+ return;
346
+ }
299
347
  let packageJson;
300
348
  try {
301
349
  const packageJsonText = fs.readFileSync("./package.json", "utf-8");
@@ -305,7 +353,7 @@ export async function action(argv) {
305
353
  console.log("Can't read/parse package.json in current directory, making no assumptions!");
306
354
  packageJson = null;
307
355
  }
308
- const options = buildOptions(packageJson, commandLineValues);
356
+ const options = buildOptions(packageJson, parsed.commandLineOptions);
309
357
  const COMPUTE_JS_DIR = options.outputDir;
310
358
  if (COMPUTE_JS_DIR == null) {
311
359
  console.error("❌ required parameter --output not provided.");
@@ -494,11 +542,11 @@ export async function action(argv) {
494
542
  },
495
543
  private: true,
496
544
  scripts: {
497
- prestart: "npx @fastly/compute-js-static-publish publish-content --local-only",
498
- start: "fastly compute serve",
499
- "publish-service": "fastly compute publish",
500
- "publish-content": 'npx @fastly/compute-js-static-publish publish-content',
501
- build: 'js-compute-runtime ./src/index.js ./bin/main.wasm'
545
+ 'dev:publish': 'npx @fastly/compute-js-static-publish publish-content --local',
546
+ 'dev:start': 'fastly compute serve',
547
+ 'fastly:deploy': 'fastly compute publish',
548
+ 'fastly:publish': 'npx @fastly/compute-js-static-publish publish-content',
549
+ 'build': 'js-compute-runtime ./src/index.js ./bin/main.wasm'
502
550
  },
503
551
  }, undefined, 2);
504
552
  // fastly.toml
@@ -534,6 +582,7 @@ const rc = {
534
582
  kvStoreName: ${JSON.stringify(kvStoreName)},
535
583
  publishId: ${JSON.stringify(publishId)},
536
584
  defaultCollectionName: ${JSON.stringify(defaultCollectionName)},
585
+ staticPublisherWorkingDir: ${JSON.stringify(dotRelative(computeJsDir, staticPublisherWorkingDir))},
537
586
  };
538
587
 
539
588
  export default rc;
@@ -585,7 +634,6 @@ export default rc;
585
634
  /** @type {import('@fastly/compute-js-static-publish').PublishContentConfig} */
586
635
  const config = {
587
636
  rootDir: ${JSON.stringify(dotRelative(computeJsDir, rootDir))},
588
- staticPublisherWorkingDir: ${JSON.stringify(dotRelative(computeJsDir, staticPublisherWorkingDir))},
589
637
  // excludeDirs: [ './node_modules' ],
590
638
  // excludeDotFiles: true,
591
639
  // includeWellKnown: true,
@@ -651,12 +699,13 @@ async function handleRequest(event) {
651
699
  console.log('To run your Compute application locally:');
652
700
  console.log('');
653
701
  console.log(' cd ' + COMPUTE_JS_DIR);
654
- console.log(' npm run start');
702
+ console.log(' npm run dev:publish');
703
+ console.log(' npm run dev:start');
655
704
  console.log('');
656
705
  console.log('To build and deploy to your Compute service:');
657
706
  console.log('');
658
707
  console.log(' cd ' + COMPUTE_JS_DIR);
659
- console.log(' npm run publish-service');
660
- console.log(' npm run publish-content');
708
+ console.log(' npm run fastly:deploy');
709
+ console.log(' npm run fastly:publish');
661
710
  console.log('');
662
711
  }
@@ -3,6 +3,14 @@
3
3
  * Copyright Fastly, Inc.
4
4
  * Licensed under the MIT license. See LICENSE file for details.
5
5
  */
6
- import { action } from './commands/index.js';
7
- console.log("🧑‍💻 Fastly Compute JavaScript Static Publisher");
8
- await action(process.argv);
6
+ import fs from 'node:fs';
7
+ import * as scaffoldCommand from './commands/scaffold/index.js';
8
+ import * as manageCommands from './commands/manage/index.js';
9
+ if (!fs.existsSync('./static-publish.rc.js')) {
10
+ console.log("🧑‍💻Fastly Compute JavaScript Static Publisher (Scaffolding mode)");
11
+ await scaffoldCommand.action(process.argv);
12
+ }
13
+ else {
14
+ console.log("🧑‍💻Fastly Compute JavaScript Static Publisher (Management mode)");
15
+ await manageCommands.action(process.argv);
16
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAwC7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
@@ -4,8 +4,7 @@
4
4
  */
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import cli from '@fastly/cli';
7
- import { makeRetryable } from '../util/retryable.js';
8
- ;
7
+ import { makeRetryable } from './retryable.js';
9
8
  export function loadApiToken(params) {
10
9
  let apiToken = null;
11
10
  let source = '';
@@ -58,6 +57,12 @@ export class FetchError extends Error {
58
57
  this.status = status;
59
58
  }
60
59
  }
60
+ function isReadableStream(data) {
61
+ return (typeof data === 'object' &&
62
+ data !== null &&
63
+ typeof data.getReader === 'function' &&
64
+ typeof data.tee === 'function');
65
+ }
61
66
  export async function callFastlyApi(fastlyApiContext, endpoint, operationName, queryParams, requestInit) {
62
67
  const url = new URL(endpoint, 'https://api.fastly.com/');
63
68
  if (queryParams != null) {
@@ -71,6 +76,7 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
71
76
  ...requestInit,
72
77
  headers,
73
78
  redirect: 'error',
79
+ ...(isReadableStream(requestInit?.body) ? { duplex: 'half' } : null),
74
80
  });
75
81
  let response;
76
82
  try {
@@ -1,16 +1,30 @@
1
+ import { type CommandLineOptions, type OptionDefinition } from 'command-line-args';
1
2
  export type ModeAction = (argv: string[]) => void | Promise<void>;
2
3
  export type ActionModule = {
3
4
  action: ModeAction;
4
5
  };
6
+ export type ActionTable<T extends string> = Record<T, ActionModule>;
5
7
  export declare function isHelpArgs(argv: string[]): boolean;
6
8
  export declare function findMainCommandNameAndArgs(argv: string[]): [string | null, string[]];
7
9
  export type CommandAndArgs<T> = {
8
10
  needHelp: false;
9
11
  command: T;
10
12
  argv: string[];
11
- } | {
13
+ };
14
+ export type CommandAndArgsHelp = {
12
15
  needHelp: true;
13
16
  command: string | null;
14
17
  };
15
- export declare function getCommandAndArgs<T extends string>(argv: string[], modes: T[]): CommandAndArgs<T>;
18
+ export type CommandAndArgsResult<T> = CommandAndArgs<T> | CommandAndArgsHelp;
19
+ export declare function getCommandAndArgs<T extends string>(argv: string[], actions: ActionTable<T>): CommandAndArgsResult<T>;
20
+ export type CommandLineParsed = {
21
+ needHelp: false;
22
+ commandLineOptions: CommandLineOptions;
23
+ };
24
+ export type CommandLineHelp = {
25
+ needHelp: true;
26
+ error: Error | null;
27
+ };
28
+ export type CommandLineResult = CommandLineParsed | CommandLineHelp;
29
+ export declare function parseCommandLine(argv: string[], optionDefinitions: OptionDefinition[]): CommandLineResult;
16
30
  //# sourceMappingURL=args.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAElD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAQxC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAepF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B;IACA,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,GACC;IACA,QAAQ,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CACA;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,CAAC,EAAE,GACT,cAAc,CAAC,CAAC,CAAC,CAiCnB"}
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"AAKA,OAAwB,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEpG,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAClD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAMpE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAKxC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAepF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;AAE7E,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,oBAAoB,CAAC,CAAC,CAAC,CAiCzB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEpE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EAAE,EACd,iBAAiB,EAAE,gBAAgB,EAAE,GACpC,iBAAiB,CA0BnB"}
@@ -3,11 +3,11 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import commandLineArgs from 'command-line-args';
6
+ const helpOptionsDefs = [
7
+ { name: 'help', alias: 'h', type: Boolean },
8
+ ];
6
9
  export function isHelpArgs(argv) {
7
- const helpDefinitions = [
8
- { name: 'help', type: Boolean, },
9
- ];
10
- const helpOptions = commandLineArgs(helpDefinitions, { argv, stopAtFirstUnknown: true });
10
+ const helpOptions = commandLineArgs(helpOptionsDefs, { argv, stopAtFirstUnknown: true });
11
11
  return !!helpOptions['help'];
12
12
  }
13
13
  export function findMainCommandNameAndArgs(argv) {
@@ -22,7 +22,7 @@ export function findMainCommandNameAndArgs(argv) {
22
22
  }
23
23
  return [command, commandArgs];
24
24
  }
25
- export function getCommandAndArgs(argv, modes) {
25
+ export function getCommandAndArgs(argv, actions) {
26
26
  if (isHelpArgs(argv)) {
27
27
  return {
28
28
  needHelp: true,
@@ -32,7 +32,7 @@ export function getCommandAndArgs(argv, modes) {
32
32
  const result = findMainCommandNameAndArgs(argv);
33
33
  const [command, actionArgv] = result;
34
34
  if (command != null) {
35
- for (const modeName of modes) {
35
+ for (const modeName of Object.keys(actions)) {
36
36
  if (command === modeName) {
37
37
  return {
38
38
  needHelp: false,
@@ -53,3 +53,29 @@ export function getCommandAndArgs(argv, modes) {
53
53
  command,
54
54
  };
55
55
  }
56
+ export function parseCommandLine(argv, optionDefinitions) {
57
+ let commandLineOptions;
58
+ try {
59
+ commandLineOptions = commandLineArgs([
60
+ ...helpOptionsDefs,
61
+ ...optionDefinitions,
62
+ ], { argv });
63
+ }
64
+ catch (err) {
65
+ const error = err instanceof Error ? err : new Error(String(err));
66
+ return {
67
+ needHelp: true,
68
+ error,
69
+ };
70
+ }
71
+ if (!!commandLineOptions['help']) {
72
+ return {
73
+ needHelp: true,
74
+ error: null,
75
+ };
76
+ }
77
+ return {
78
+ needHelp: false,
79
+ commandLineOptions,
80
+ };
81
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/util/config.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACtG,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA2B1E;AAGD,eAAO,MAAM,0BAA0B,6DA2CrC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAyB9G;AA4CD,eAAO,MAAM,6BAA6B,4EAuKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/util/config.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACtG,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA2B1E;AAGD,eAAO,MAAM,0BAA0B,6DA+DrC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAyB9G;AA4CD,eAAO,MAAM,6BAA6B,4EAmJxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
@@ -34,7 +34,7 @@ export async function loadStaticPublisherRcFile() {
34
34
  return config;
35
35
  }
36
36
  export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((config, errors) => {
37
- let { kvStoreName, publishId, defaultCollectionName, } = config;
37
+ let { kvStoreName, publishId, defaultCollectionName, staticPublisherWorkingDir, } = config;
38
38
  if (!isSpecified(config, 'kvStoreName')) {
39
39
  errors.push('kvStoreName must be specified.');
40
40
  }
@@ -68,10 +68,27 @@ export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((confi
68
68
  errors.push('defaultCollectionName must be a non-empty string.');
69
69
  }
70
70
  }
71
+ if (!isSpecified(config, 'staticPublisherWorkingDir')) {
72
+ errors.push('staticPublisherWorkingDir must be specified.');
73
+ }
74
+ else {
75
+ if (staticPublisherWorkingDir.startsWith('./') &&
76
+ staticPublisherWorkingDir !== './' &&
77
+ !staticPublisherWorkingDir.includes('//')) {
78
+ // ok
79
+ }
80
+ else {
81
+ errors.push('staticPublisherWorkingDir must be a relative subdirectory.');
82
+ }
83
+ while (staticPublisherWorkingDir.endsWith('/')) {
84
+ staticPublisherWorkingDir = staticPublisherWorkingDir.slice(0, -1);
85
+ }
86
+ }
71
87
  return {
72
88
  kvStoreName,
73
89
  publishId,
74
90
  defaultCollectionName,
91
+ staticPublisherWorkingDir,
75
92
  };
76
93
  });
77
94
  export async function loadPublishContentConfigFile(configFile) {
@@ -133,7 +150,7 @@ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors)
133
150
  return normalizeContentTypeDef(config, errors);
134
151
  });
135
152
  export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
136
- let { rootDir, staticPublisherWorkingDir, excludeDirs, excludeDotFiles, includeWellKnown, kvStoreAssetInclusionTest, contentCompression, contentTypes, server, } = config;
153
+ let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, kvStoreAssetInclusionTest, contentCompression, contentTypes, server, } = config;
137
154
  if (!isSpecified(config, 'rootDir')) {
138
155
  errors.push('rootDir must be specified.');
139
156
  }
@@ -145,22 +162,6 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
145
162
  errors.push('rootDir must be a non-empty string.');
146
163
  }
147
164
  }
148
- if (!isSpecified(config, 'staticPublisherWorkingDir')) {
149
- errors.push('staticPublisherWorkingDir must be specified.');
150
- }
151
- else {
152
- if (staticPublisherWorkingDir.startsWith('./') &&
153
- staticPublisherWorkingDir !== './' &&
154
- !staticPublisherWorkingDir.includes('//')) {
155
- // ok
156
- }
157
- else {
158
- errors.push('staticPublisherWorkingDir must be a relative subdirectory.');
159
- }
160
- while (staticPublisherWorkingDir.endsWith('/')) {
161
- staticPublisherWorkingDir = staticPublisherWorkingDir.slice(0, -1);
162
- }
163
- }
164
165
  if (!isSpecified(config, 'excludeDotFiles')) {
165
166
  excludeDotFiles = true;
166
167
  }
@@ -284,7 +285,6 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
284
285
  }
285
286
  return {
286
287
  rootDir,
287
- staticPublisherWorkingDir,
288
288
  excludeDirs,
289
289
  excludeDotFiles,
290
290
  includeWellKnown,
@@ -0,0 +1,2 @@
1
+ export declare function readServiceId(filePath: string): string | undefined;
2
+ //# sourceMappingURL=fastly-toml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastly-toml.d.ts","sourceRoot":"","sources":["../../../src/cli/util/fastly-toml.ts"],"names":[],"mappings":"AAQA,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,sBAQ7C"}
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import fs from 'fs';
6
+ import toml from 'toml';
7
+ export function readServiceId(filePath) {
8
+ const text = fs.readFileSync(filePath, 'utf8');
9
+ const parsed = toml.parse(text);
10
+ const serviceId = parsed.service_id;
11
+ if (typeof serviceId === 'string') {
12
+ return serviceId;
13
+ }
14
+ return undefined;
15
+ }
@@ -1,4 +1,6 @@
1
- import { type FastlyApiContext } from '../fastly-api/api-token.js';
1
+ export declare function doKvStoreItemsOperation<TObject extends {
2
+ key: string;
3
+ }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
2
4
  export type KVStoreItemDesc = {
3
5
  write: boolean;
4
6
  size: number;
@@ -6,7 +8,6 @@ export type KVStoreItemDesc = {
6
8
  filePath: string;
7
9
  metadataJson?: Record<string, any>;
8
10
  };
9
- export declare function uploadFilesToKVStore(fastlyApiContext: FastlyApiContext, kvStoreName: string, kvStoreItemDescriptions: KVStoreItemDesc[]): Promise<void>;
10
11
  export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: KVStoreItemDesc, chunkSize: number): boolean;
11
12
  export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: KVStoreItemDesc[], chunkSize: number): Promise<void>;
12
13
  //# sourceMappingURL=kv-store-items.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,4BAA4B,CAAC;AAG/E,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,iBAgD7I;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAkClH;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoG5G"}
1
+ {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAUA,wBAAsB,uBAAuB,CAAC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAC3E,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,iBA6C3B;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAkClH;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoG5G"}
@@ -3,26 +3,20 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import fs from 'node:fs';
6
- import { directoryExists, getFileSize, rootRelative } from './files.js';
6
+ import { directoryExists, getFileSize } from './files.js';
7
7
  import { attemptWithRetries } from './retryable.js';
8
- import { FetchError } from '../fastly-api/api-token.js';
9
- import { kvStoreSubmitFile } from '../fastly-api/kv-store.js';
10
- export async function uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItemDescriptions) {
11
- const maxConcurrent = 12;
8
+ import { FetchError } from './api-token.js';
9
+ export async function doKvStoreItemsOperation(objects, fn, maxConcurrent = 12) {
12
10
  let index = 0; // Shared among workers
13
11
  async function worker() {
14
- while (index < kvStoreItemDescriptions.length) {
12
+ while (index < objects.length) {
15
13
  const currentIndex = index;
16
14
  index = index + 1;
17
- const { write, key, filePath, metadataJson } = kvStoreItemDescriptions[currentIndex];
18
- if (!write) {
19
- continue;
20
- }
15
+ const object = objects[currentIndex];
16
+ const { key } = object;
21
17
  try {
22
18
  await attemptWithRetries(async () => {
23
- const fileBytes = fs.readFileSync(filePath);
24
- await kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
25
- console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
19
+ await fn(object, key, currentIndex);
26
20
  }, {
27
21
  onAttempt(attempt) {
28
22
  if (attempt > 0) {
@@ -1,3 +1,11 @@
1
1
  import { type KVStoreItemDesc } from './kv-store-items.js';
2
+ export declare function getLocalKVStoreKeys(storeFile: string, prefix?: string): Promise<string[]>;
3
+ export declare function getLocalKvStoreEntry(storeFile: string, key: string, metadataOnly?: boolean): Promise<{
4
+ metadata: string | null;
5
+ generation: null;
6
+ response: Response;
7
+ } | null>;
8
+ export declare function localKvStoreSubmitEntry(storeFile: string, key: string, file: string, metadata: string | undefined): Promise<void>;
9
+ export declare function localKvStoreDeleteEntry(storeFile: string, key: string): Promise<void>;
2
10
  export declare function writeKVStoreEntriesForLocal(storeFile: string, computeAppDir: string, kvStoreItemDescriptions: KVStoreItemDesc[]): void;
3
11
  //# sourceMappingURL=kv-store-local-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-local-server.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-local-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,uBAAuB,EAAE,eAAe,EAAE,QAmC/H"}
1
+ {"version":3,"file":"kv-store-local-server.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-local-server.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAK3D,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,qBAoBhB;AAED,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO;;;;UAgCvB;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAmB7B;AAED,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,iBAgBZ;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,uBAAuB,EAAE,eAAe,EAAE,QAiC3C"}