@motionskit/cli 0.2.2 → 0.2.4
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 +10 -2
- package/dist/index.js +99 -1
- package/dist/main.js +105 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FixtureEntry, SourceVersion, MotionVersion, Json } from '@motionskit/kernel';
|
|
1
|
+
import { FixtureEntry, SourceVersion, MotionVersion, Json, MotionHandleWarning } from '@motionskit/kernel';
|
|
2
2
|
|
|
3
3
|
/** `tenant.yaml`'s `sources.fixtures` switch and every entry of `fixtures/sources/*.json`, in the order the gateway matches them. */
|
|
4
4
|
type TenantFixtures = {
|
|
@@ -50,4 +50,12 @@ declare function compileMotion(tenant: {
|
|
|
50
50
|
}, dir: string): Promise<Compiled>;
|
|
51
51
|
declare function compileTenant(tenantDir: string): Promise<Tenant>;
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
type PublishWarningsInput = {
|
|
54
|
+
warning?: string;
|
|
55
|
+
unknownHandles?: MotionHandleWarning[];
|
|
56
|
+
memberHandles?: string[];
|
|
57
|
+
};
|
|
58
|
+
/** Formats non-blocking warnings returned when publishing a motion version. */
|
|
59
|
+
declare function formatPublishWarnings(tenant: string, motion: string, out: PublishWarningsInput): string[];
|
|
60
|
+
|
|
61
|
+
export { type Compiled, type CompiledSource, type PublishWarningsInput, type Tenant, compileMotion, compileSource, compileSources, compileTenant, findTenantDir, formatPublishWarnings, monorepoTenants, tenantIdentity, tenantsDir };
|
package/dist/index.js
CHANGED
|
@@ -263,6 +263,67 @@ function ttlSeconds(ttl) {
|
|
|
263
263
|
const ms = typeof ttl === "string" ? parseDuration2(ttl) : null;
|
|
264
264
|
return ms === null ? `ttl must be a duration such as "7d" or "12h", or seconds, got ${JSON.stringify(ttl)}` : Math.round(ms / 1e3);
|
|
265
265
|
}
|
|
266
|
+
var PACE_KEYS = /* @__PURE__ */ new Set(["requests", "per", "concurrency"]);
|
|
267
|
+
function parsePaceMs(per) {
|
|
268
|
+
if (typeof per === "number") return Number.isInteger(per) && per > 0 ? per : `per must be a positive integer in ms or a duration such as "1s", got ${per}`;
|
|
269
|
+
if (typeof per === "string") {
|
|
270
|
+
const msMatch = /^(\d+)\s*ms$/.exec(per.trim());
|
|
271
|
+
if (msMatch) return Number(msMatch[1]);
|
|
272
|
+
const ms = parseDuration2(per);
|
|
273
|
+
if (ms !== null) return ms;
|
|
274
|
+
}
|
|
275
|
+
return `per must be a duration such as "1s" or "10s", or milliseconds, got ${JSON.stringify(per)}`;
|
|
276
|
+
}
|
|
277
|
+
function isInlinePaceSpec(v) {
|
|
278
|
+
const keys = Object.keys(v);
|
|
279
|
+
return keys.length > 0 && keys.every((k) => PACE_KEYS.has(k)) && keys.every((k) => typeof v[k] !== "object" || v[k] === null);
|
|
280
|
+
}
|
|
281
|
+
function normalizeBucketSpec(where2, raw, errors) {
|
|
282
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
283
|
+
errors.push(`${where2}: pace must be an object`);
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const obj = raw;
|
|
287
|
+
const extra = Object.keys(obj).filter((k) => !PACE_KEYS.has(k));
|
|
288
|
+
if (extra.length) {
|
|
289
|
+
errors.push(`${where2}: unknown pace field${extra.length > 1 ? "s" : ""} ${extra.join(", ")}`);
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
const spec = {};
|
|
293
|
+
if (obj.requests !== void 0) spec.requests = obj.requests;
|
|
294
|
+
if (obj.per !== void 0) {
|
|
295
|
+
const perMs = parsePaceMs(obj.per);
|
|
296
|
+
if (typeof perMs === "string") {
|
|
297
|
+
errors.push(`${where2}: ${perMs}`);
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
spec.perMs = perMs;
|
|
301
|
+
}
|
|
302
|
+
if (obj.concurrency !== void 0) spec.concurrency = obj.concurrency;
|
|
303
|
+
return spec;
|
|
304
|
+
}
|
|
305
|
+
function normalizeSourcePace(raw, errors) {
|
|
306
|
+
if (raw === void 0) return {};
|
|
307
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
308
|
+
errors.push("pace must be a bucket spec or a map of named buckets");
|
|
309
|
+
return {};
|
|
310
|
+
}
|
|
311
|
+
const obj = raw;
|
|
312
|
+
if (!Object.keys(obj).length) {
|
|
313
|
+
errors.push("pace must declare at least one bucket");
|
|
314
|
+
return {};
|
|
315
|
+
}
|
|
316
|
+
if (isInlinePaceSpec(obj)) {
|
|
317
|
+
const spec = normalizeBucketSpec("bucket default", obj, errors);
|
|
318
|
+
return spec ? { default: spec } : {};
|
|
319
|
+
}
|
|
320
|
+
const out = {};
|
|
321
|
+
for (const [name, entry] of Object.entries(obj)) {
|
|
322
|
+
const spec = normalizeBucketSpec(`bucket ${name}`, entry, errors);
|
|
323
|
+
if (spec) out[name] = spec;
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
266
327
|
async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
267
328
|
const tenantDir = resolve(tenantRoot);
|
|
268
329
|
const id2 = folderName(dir);
|
|
@@ -286,6 +347,8 @@ async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
|
286
347
|
if (def?.kind !== "source") throw new SourceErrors(where2, ["index.ts must `export default defineSource({ \u2026 })`"]);
|
|
287
348
|
const errors = [];
|
|
288
349
|
if (def.id !== id2) errors.push(`the source's id "${def.id}" must match its folder, sources/${id2}`);
|
|
350
|
+
const buckets = normalizeSourcePace(def.pace, errors);
|
|
351
|
+
const hasDefaultBucket = Object.hasOwn(buckets, "default");
|
|
289
352
|
const ops = {};
|
|
290
353
|
for (const [name, op] of Object.entries(def.ops ?? {})) {
|
|
291
354
|
if (!op?.input || typeof op.input !== "object" || !("~standard" in op.input))
|
|
@@ -293,7 +356,25 @@ async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
|
293
356
|
if (typeof op?.call !== "function") errors.push(`op ${name}: call must be a function`);
|
|
294
357
|
const ttl = ttlSeconds(op?.ttl);
|
|
295
358
|
if (typeof ttl === "string") errors.push(`op ${name}: ${ttl}`);
|
|
296
|
-
|
|
359
|
+
let opBuckets;
|
|
360
|
+
if (op?.pace === void 0) {
|
|
361
|
+
if (hasDefaultBucket) opBuckets = ["default"];
|
|
362
|
+
} else if (op.pace === false) {
|
|
363
|
+
opBuckets = void 0;
|
|
364
|
+
} else if (Array.isArray(op.pace)) {
|
|
365
|
+
if (!op.pace.length || op.pace.some((b) => typeof b !== "string")) errors.push(`op ${name}: pace list must be a non-empty array of bucket names`);
|
|
366
|
+
else opBuckets = [...op.pace];
|
|
367
|
+
} else if (typeof op.pace === "object" && op.pace !== null) {
|
|
368
|
+
const bucketKey = Object.hasOwn(buckets, name) ? `op_${name}` : name;
|
|
369
|
+
const spec = normalizeBucketSpec(`op ${name}`, op.pace, errors);
|
|
370
|
+
if (spec) {
|
|
371
|
+
buckets[bucketKey] = spec;
|
|
372
|
+
opBuckets = [bucketKey];
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
errors.push(`op ${name}: pace must be false, a list of bucket names, or { requests, per, concurrency }`);
|
|
376
|
+
}
|
|
377
|
+
ops[name] = { ttlSeconds: typeof ttl === "number" ? ttl : 0, ...opBuckets ? { buckets: opBuckets } : {} };
|
|
297
378
|
}
|
|
298
379
|
const out = await build(
|
|
299
380
|
options(
|
|
@@ -313,6 +394,7 @@ export default serveSource(def);
|
|
|
313
394
|
title: yaml.data?.title ?? def.title ?? id2,
|
|
314
395
|
hosts: [...def.hosts ?? []],
|
|
315
396
|
secrets: [...def.secrets ?? []],
|
|
397
|
+
...Object.keys(buckets).length ? { buckets } : {},
|
|
316
398
|
ops,
|
|
317
399
|
bundle: sha256(bundle2)
|
|
318
400
|
};
|
|
@@ -475,12 +557,28 @@ async function compileTenant(tenantDir) {
|
|
|
475
557
|
}
|
|
476
558
|
return { id: id2, title: meta.title ?? id2, timezone, connection, seed, sources: await compileSources(dir, id2), fixtures, motions };
|
|
477
559
|
}
|
|
560
|
+
|
|
561
|
+
// src/publish.ts
|
|
562
|
+
function formatPublishWarnings(tenant, motion, out) {
|
|
563
|
+
const lines = [];
|
|
564
|
+
if (out.warning) lines.push(`warning: ${out.warning}`);
|
|
565
|
+
const unknown = out.unknownHandles ?? [];
|
|
566
|
+
if (!unknown.length) return lines;
|
|
567
|
+
const noun = unknown.length === 1 ? "handle" : "handles";
|
|
568
|
+
const members = out.memberHandles?.length ? `members: ${out.memberHandles.map((h) => `@${h}`).join(", ")}` : `no members in ${tenant}`;
|
|
569
|
+
lines.push(`warning: unknown member ${noun} in ${tenant}/${motion} (${members}):`);
|
|
570
|
+
for (const item of unknown) {
|
|
571
|
+
lines.push(` @${item.handle} is not a member of ${tenant} (${item.references.join(", ")})`);
|
|
572
|
+
}
|
|
573
|
+
return lines;
|
|
574
|
+
}
|
|
478
575
|
export {
|
|
479
576
|
compileMotion,
|
|
480
577
|
compileSource,
|
|
481
578
|
compileSources,
|
|
482
579
|
compileTenant,
|
|
483
580
|
findTenantDir,
|
|
581
|
+
formatPublishWarnings,
|
|
484
582
|
monorepoTenants,
|
|
485
583
|
tenantIdentity,
|
|
486
584
|
tenantsDir
|
package/dist/main.js
CHANGED
|
@@ -452,6 +452,67 @@ function ttlSeconds(ttl) {
|
|
|
452
452
|
const ms = typeof ttl === "string" ? parseDuration2(ttl) : null;
|
|
453
453
|
return ms === null ? `ttl must be a duration such as "7d" or "12h", or seconds, got ${JSON.stringify(ttl)}` : Math.round(ms / 1e3);
|
|
454
454
|
}
|
|
455
|
+
var PACE_KEYS = /* @__PURE__ */ new Set(["requests", "per", "concurrency"]);
|
|
456
|
+
function parsePaceMs(per) {
|
|
457
|
+
if (typeof per === "number") return Number.isInteger(per) && per > 0 ? per : `per must be a positive integer in ms or a duration such as "1s", got ${per}`;
|
|
458
|
+
if (typeof per === "string") {
|
|
459
|
+
const msMatch = /^(\d+)\s*ms$/.exec(per.trim());
|
|
460
|
+
if (msMatch) return Number(msMatch[1]);
|
|
461
|
+
const ms = parseDuration2(per);
|
|
462
|
+
if (ms !== null) return ms;
|
|
463
|
+
}
|
|
464
|
+
return `per must be a duration such as "1s" or "10s", or milliseconds, got ${JSON.stringify(per)}`;
|
|
465
|
+
}
|
|
466
|
+
function isInlinePaceSpec(v) {
|
|
467
|
+
const keys = Object.keys(v);
|
|
468
|
+
return keys.length > 0 && keys.every((k) => PACE_KEYS.has(k)) && keys.every((k) => typeof v[k] !== "object" || v[k] === null);
|
|
469
|
+
}
|
|
470
|
+
function normalizeBucketSpec(where2, raw, errors) {
|
|
471
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
472
|
+
errors.push(`${where2}: pace must be an object`);
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
const obj = raw;
|
|
476
|
+
const extra = Object.keys(obj).filter((k) => !PACE_KEYS.has(k));
|
|
477
|
+
if (extra.length) {
|
|
478
|
+
errors.push(`${where2}: unknown pace field${extra.length > 1 ? "s" : ""} ${extra.join(", ")}`);
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
const spec = {};
|
|
482
|
+
if (obj.requests !== void 0) spec.requests = obj.requests;
|
|
483
|
+
if (obj.per !== void 0) {
|
|
484
|
+
const perMs = parsePaceMs(obj.per);
|
|
485
|
+
if (typeof perMs === "string") {
|
|
486
|
+
errors.push(`${where2}: ${perMs}`);
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
spec.perMs = perMs;
|
|
490
|
+
}
|
|
491
|
+
if (obj.concurrency !== void 0) spec.concurrency = obj.concurrency;
|
|
492
|
+
return spec;
|
|
493
|
+
}
|
|
494
|
+
function normalizeSourcePace(raw, errors) {
|
|
495
|
+
if (raw === void 0) return {};
|
|
496
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
497
|
+
errors.push("pace must be a bucket spec or a map of named buckets");
|
|
498
|
+
return {};
|
|
499
|
+
}
|
|
500
|
+
const obj = raw;
|
|
501
|
+
if (!Object.keys(obj).length) {
|
|
502
|
+
errors.push("pace must declare at least one bucket");
|
|
503
|
+
return {};
|
|
504
|
+
}
|
|
505
|
+
if (isInlinePaceSpec(obj)) {
|
|
506
|
+
const spec = normalizeBucketSpec("bucket default", obj, errors);
|
|
507
|
+
return spec ? { default: spec } : {};
|
|
508
|
+
}
|
|
509
|
+
const out = {};
|
|
510
|
+
for (const [name, entry] of Object.entries(obj)) {
|
|
511
|
+
const spec = normalizeBucketSpec(`bucket ${name}`, entry, errors);
|
|
512
|
+
if (spec) out[name] = spec;
|
|
513
|
+
}
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
455
516
|
async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
456
517
|
const tenantDir = resolve(tenantRoot);
|
|
457
518
|
const id2 = folderName(dir);
|
|
@@ -475,6 +536,8 @@ async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
|
475
536
|
if (def?.kind !== "source") throw new SourceErrors(where2, ["index.ts must `export default defineSource({ \u2026 })`"]);
|
|
476
537
|
const errors = [];
|
|
477
538
|
if (def.id !== id2) errors.push(`the source's id "${def.id}" must match its folder, sources/${id2}`);
|
|
539
|
+
const buckets = normalizeSourcePace(def.pace, errors);
|
|
540
|
+
const hasDefaultBucket = Object.hasOwn(buckets, "default");
|
|
478
541
|
const ops = {};
|
|
479
542
|
for (const [name, op] of Object.entries(def.ops ?? {})) {
|
|
480
543
|
if (!op?.input || typeof op.input !== "object" || !("~standard" in op.input))
|
|
@@ -482,7 +545,25 @@ async function compileSource(tenant, dir, tenantRoot = resolve(dir, "../..")) {
|
|
|
482
545
|
if (typeof op?.call !== "function") errors.push(`op ${name}: call must be a function`);
|
|
483
546
|
const ttl = ttlSeconds(op?.ttl);
|
|
484
547
|
if (typeof ttl === "string") errors.push(`op ${name}: ${ttl}`);
|
|
485
|
-
|
|
548
|
+
let opBuckets;
|
|
549
|
+
if (op?.pace === void 0) {
|
|
550
|
+
if (hasDefaultBucket) opBuckets = ["default"];
|
|
551
|
+
} else if (op.pace === false) {
|
|
552
|
+
opBuckets = void 0;
|
|
553
|
+
} else if (Array.isArray(op.pace)) {
|
|
554
|
+
if (!op.pace.length || op.pace.some((b) => typeof b !== "string")) errors.push(`op ${name}: pace list must be a non-empty array of bucket names`);
|
|
555
|
+
else opBuckets = [...op.pace];
|
|
556
|
+
} else if (typeof op.pace === "object" && op.pace !== null) {
|
|
557
|
+
const bucketKey = Object.hasOwn(buckets, name) ? `op_${name}` : name;
|
|
558
|
+
const spec = normalizeBucketSpec(`op ${name}`, op.pace, errors);
|
|
559
|
+
if (spec) {
|
|
560
|
+
buckets[bucketKey] = spec;
|
|
561
|
+
opBuckets = [bucketKey];
|
|
562
|
+
}
|
|
563
|
+
} else {
|
|
564
|
+
errors.push(`op ${name}: pace must be false, a list of bucket names, or { requests, per, concurrency }`);
|
|
565
|
+
}
|
|
566
|
+
ops[name] = { ttlSeconds: typeof ttl === "number" ? ttl : 0, ...opBuckets ? { buckets: opBuckets } : {} };
|
|
486
567
|
}
|
|
487
568
|
const out = await build(
|
|
488
569
|
options(
|
|
@@ -502,6 +583,7 @@ export default serveSource(def);
|
|
|
502
583
|
title: yaml.data?.title ?? def.title ?? id2,
|
|
503
584
|
hosts: [...def.hosts ?? []],
|
|
504
585
|
secrets: [...def.secrets ?? []],
|
|
586
|
+
...Object.keys(buckets).length ? { buckets } : {},
|
|
505
587
|
ops,
|
|
506
588
|
bundle: sha256(bundle2)
|
|
507
589
|
};
|
|
@@ -543,10 +625,14 @@ function writeSourceTypes(tenantDir, sources) {
|
|
|
543
625
|
}
|
|
544
626
|
function reportSources(sources) {
|
|
545
627
|
for (const { manifest: m, bundle: bundle2 } of sources) {
|
|
628
|
+
const bucketSummary = m.buckets ? ` pace=[${Object.keys(m.buckets).join(", ")}]` : "";
|
|
546
629
|
console.log(
|
|
547
|
-
` source ${m.source} @ ${m.sha.slice(0, 10)} ${(bundle2.length / 1024).toFixed(0)} KB, hosts=[${m.hosts.join(", ")}] secrets=[${m.secrets.join(", ")}]`
|
|
630
|
+
` source ${m.source} @ ${m.sha.slice(0, 10)} ${(bundle2.length / 1024).toFixed(0)} KB, hosts=[${m.hosts.join(", ")}] secrets=[${m.secrets.join(", ")}]${bucketSummary}`
|
|
548
631
|
);
|
|
549
|
-
for (const [op, { ttlSeconds: ttlSeconds2 }] of Object.entries(m.ops))
|
|
632
|
+
for (const [op, { ttlSeconds: ttlSeconds2, buckets }] of Object.entries(m.ops)) {
|
|
633
|
+
const pace = buckets?.length ? ` pace=[${buckets.join(", ")}]` : "";
|
|
634
|
+
console.log(` op ${m.source}.${op}${ttlSeconds2 ? ` ttl=${ttlSeconds2}s` : ""}${pace}`);
|
|
635
|
+
}
|
|
550
636
|
}
|
|
551
637
|
}
|
|
552
638
|
async function publishSources(post, tenant, sources, opts) {
|
|
@@ -897,6 +983,21 @@ function origin(dir, env = process.env) {
|
|
|
897
983
|
return { kind: "cli", ...repo ? { repo } : {}, commit, dirty: !!git(dir, "status", "--porcelain", "--", ".") };
|
|
898
984
|
}
|
|
899
985
|
|
|
986
|
+
// src/publish.ts
|
|
987
|
+
function formatPublishWarnings(tenant, motion, out) {
|
|
988
|
+
const lines = [];
|
|
989
|
+
if (out.warning) lines.push(`warning: ${out.warning}`);
|
|
990
|
+
const unknown = out.unknownHandles ?? [];
|
|
991
|
+
if (!unknown.length) return lines;
|
|
992
|
+
const noun = unknown.length === 1 ? "handle" : "handles";
|
|
993
|
+
const members = out.memberHandles?.length ? `members: ${out.memberHandles.map((h) => `@${h}`).join(", ")}` : `no members in ${tenant}`;
|
|
994
|
+
lines.push(`warning: unknown member ${noun} in ${tenant}/${motion} (${members}):`);
|
|
995
|
+
for (const item of unknown) {
|
|
996
|
+
lines.push(` @${item.handle} is not a member of ${tenant} (${item.references.join(", ")})`);
|
|
997
|
+
}
|
|
998
|
+
return lines;
|
|
999
|
+
}
|
|
1000
|
+
|
|
900
1001
|
// src/tree.ts
|
|
901
1002
|
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
|
|
902
1003
|
import { join as join7, relative as relative3, resolve as resolve4, sep as sep3 } from "path";
|
|
@@ -1078,7 +1179,7 @@ async function pushDirs(dirs, live) {
|
|
|
1078
1179
|
});
|
|
1079
1180
|
console.log(`${tenant.id}/${manifest.motion} @ ${manifest.sha.slice(0, 10)} (${out.created ? "new" : "unchanged"}, ${out.live ? "live" : "draft"})`);
|
|
1080
1181
|
console.log(` ${versionLink(tenant.id, manifest.motion, manifest.sha)}`);
|
|
1081
|
-
|
|
1182
|
+
for (const line of formatPublishWarnings(tenant.id, manifest.motion, out)) console.log(line);
|
|
1082
1183
|
}
|
|
1083
1184
|
}
|
|
1084
1185
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionskit/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"esbuild": "^0.28.2",
|
|
30
30
|
"yaml": "^2.9.1",
|
|
31
31
|
"zod": "^4.6.7",
|
|
32
|
-
"@motionskit/kernel": "0.2.
|
|
32
|
+
"@motionskit/kernel": "0.2.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^22.19.0",
|