@cms0/cms0 0.2.20 → 0.2.22

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 (33) hide show
  1. package/README.md +11 -0
  2. package/dist/cjs/custom-types/registry.cjs +6 -0
  3. package/dist/cjs/index.cjs +400 -65
  4. package/dist/cjs/libs/cli/config-loader.cjs +45 -4
  5. package/dist/cjs/libs/cli/publisher.cjs +24 -11
  6. package/dist/esm/custom-types/registry.js +6 -0
  7. package/dist/esm/index.js +401 -66
  8. package/dist/esm/libs/cli/config-loader.js +45 -4
  9. package/dist/esm/libs/cli/publisher.js +24 -11
  10. package/dist/types/custom-types/index.d.ts +2 -1
  11. package/dist/types/custom-types/index.d.ts.map +1 -1
  12. package/dist/types/custom-types/registry.d.ts.map +1 -1
  13. package/dist/types/index.d.ts +131 -7
  14. package/dist/types/index.d.ts.map +1 -1
  15. package/dist/types/libs/cli/config-loader.d.ts.map +1 -1
  16. package/dist/types/libs/cli/publisher.d.ts.map +1 -1
  17. package/package.json +13 -9
  18. package/dist/cjs/index-old-1.cjs +0 -866
  19. package/dist/cjs/index-old.cjs +0 -1016
  20. package/dist/cjs/libs/cli/descriptor-builder.cjs +0 -273
  21. package/dist/cjs/utils/index.cjs +0 -2
  22. package/dist/esm/index-old-1.js +0 -862
  23. package/dist/esm/index-old.js +0 -1012
  24. package/dist/esm/libs/cli/descriptor-builder.js +0 -268
  25. package/dist/esm/utils/index.js +0 -1
  26. package/dist/types/index-old-1.d.ts +0 -175
  27. package/dist/types/index-old-1.d.ts.map +0 -1
  28. package/dist/types/index-old.d.ts +0 -151
  29. package/dist/types/index-old.d.ts.map +0 -1
  30. package/dist/types/libs/cli/descriptor-builder.d.ts +0 -5
  31. package/dist/types/libs/cli/descriptor-builder.d.ts.map +0 -1
  32. package/dist/types/utils/index.d.ts +0 -2
  33. package/dist/types/utils/index.d.ts.map +0 -1
@@ -46,6 +46,7 @@ const fs_1 = __importDefault(require("fs"));
46
46
  const path_1 = __importDefault(require("path"));
47
47
  const url_1 = require("url");
48
48
  const crypto_1 = __importDefault(require("crypto"));
49
+ const module_1 = require("module");
49
50
  const DEFAULT_CONFIG_BASENAMES = [
50
51
  "cms0.config.ts",
51
52
  "cms0.config.js",
@@ -145,9 +146,7 @@ function resolvePaths(cfgPath, config) {
145
146
  }
146
147
  const baseDir = path_1.default.dirname(cfgPath);
147
148
  const packageJsonPath = findNearestPackageJson(cfgPath);
148
- const projectRoot = packageJsonPath
149
- ? path_1.default.dirname(packageJsonPath)
150
- : baseDir;
149
+ const projectRoot = packageJsonPath ? path_1.default.dirname(packageJsonPath) : baseDir;
151
150
  const entryFile = path_1.default.resolve(baseDir, config.entry);
152
151
  const tsconfigPath = config.tsconfig
153
152
  ? path_1.default.resolve(baseDir, config.tsconfig)
@@ -178,7 +177,7 @@ function findTsConfig(entryFile) {
178
177
  return undefined;
179
178
  }
180
179
  async function transpileTsModuleToTemp(tsPath, format) {
181
- const ts = await Promise.resolve().then(() => __importStar(require("typescript")));
180
+ const ts = await loadTypescriptCompiler(tsPath);
182
181
  const source = fs_1.default.readFileSync(tsPath, "utf8");
183
182
  const transpiled = ts.transpileModule(source, {
184
183
  compilerOptions: {
@@ -204,3 +203,45 @@ function cleanupTempModule(tempPath) {
204
203
  // ignore cleanup failures
205
204
  }
206
205
  }
206
+ async function loadTypescriptCompiler(tsPath) {
207
+ const attemptedErrors = [];
208
+ const manifestCandidates = [
209
+ findNearestPackageJson(tsPath),
210
+ path_1.default.join(process.cwd(), "package.json"),
211
+ ].filter((candidate) => Boolean(candidate && fs_1.default.existsSync(candidate)));
212
+ for (const manifest of manifestCandidates) {
213
+ try {
214
+ const resolver = (0, module_1.createRequire)(manifest);
215
+ const mod = resolver("typescript");
216
+ return normalizeTypescriptModule(mod);
217
+ }
218
+ catch (error) {
219
+ attemptedErrors.push(error);
220
+ }
221
+ }
222
+ try {
223
+ const mod = (0, module_1.createRequire)(path_1.default.resolve("package.json"))("typescript");
224
+ return normalizeTypescriptModule(mod);
225
+ }
226
+ catch (error) {
227
+ attemptedErrors.push(error);
228
+ }
229
+ try {
230
+ const mod = await Promise.resolve().then(() => __importStar(require("typescript")));
231
+ return normalizeTypescriptModule(mod);
232
+ }
233
+ catch (error) {
234
+ attemptedErrors.push(error);
235
+ }
236
+ throw new AggregateError(attemptedErrors, 'cms0: Unable to resolve the "typescript" package required to load cms0.config.* files. Ensure it is installed in your project.');
237
+ }
238
+ function normalizeTypescriptModule(mod) {
239
+ if (mod && typeof mod.transpileModule === "function") {
240
+ return mod;
241
+ }
242
+ const candidate = mod?.default;
243
+ if (candidate && typeof candidate.transpileModule === "function") {
244
+ return candidate;
245
+ }
246
+ throw new Error("cms0: resolved 'typescript' module does not provide transpileModule");
247
+ }
@@ -20,6 +20,17 @@ function shouldRetryPublishError(error) {
20
20
  }
21
21
  return true;
22
22
  }
23
+ function trimTrailingSlashes(value) {
24
+ return value.replace(/\/+$/, "");
25
+ }
26
+ function buildSchemaPublishUrl(baseUrl) {
27
+ const normalized = trimTrailingSlashes(baseUrl);
28
+ return `${normalized}/schema`;
29
+ }
30
+ function buildHealthUrls(baseUrl) {
31
+ const normalized = trimTrailingSlashes(baseUrl);
32
+ return [`${normalized}/health`];
33
+ }
23
34
  const startSpinner = (label) => {
24
35
  if (!process.stdout.isTTY) {
25
36
  console.log(`${label}...`);
@@ -47,7 +58,7 @@ const startSpinner = (label) => {
47
58
  };
48
59
  };
49
60
  async function waitForAdminReady(baseUrl, headers) {
50
- const healthUrl = `${baseUrl.replace(/\/$/, "")}/ok`;
61
+ const healthUrls = buildHealthUrls(baseUrl);
51
62
  const maxWaitMs = 30_000;
52
63
  const startedAt = Date.now();
53
64
  const spinner = startSpinner("cms0: waiting for admin to reload");
@@ -55,15 +66,17 @@ async function waitForAdminReady(baseUrl, headers) {
55
66
  let attempt = 0;
56
67
  while (Date.now() - startedAt < maxWaitMs) {
57
68
  attempt += 1;
58
- try {
59
- const res = await fetch(healthUrl, { headers });
60
- if (res.ok) {
61
- spinner.stop("cms0: admin ready");
62
- return true;
69
+ for (const healthUrl of healthUrls) {
70
+ try {
71
+ const res = await fetch(healthUrl, { headers });
72
+ if (res.ok) {
73
+ spinner.stop("cms0: admin ready");
74
+ return true;
75
+ }
76
+ }
77
+ catch {
78
+ // ignore transient errors during restart
63
79
  }
64
- }
65
- catch {
66
- // ignore transient errors during restart
67
80
  }
68
81
  await sleep(Math.min(500 + attempt * 250, 2000));
69
82
  }
@@ -84,7 +97,7 @@ async function publishDescriptor(resolved, descriptor) {
84
97
  if (resolved.apiKey) {
85
98
  headers["Authorization"] = `Bearer ${resolved.apiKey}`;
86
99
  }
87
- const target = `${resolved.apiBaseUrl.replace(/\/$/, "")}/schema`;
100
+ const target = buildSchemaPublishUrl(resolved.apiBaseUrl);
88
101
  const maxAttempts = 5;
89
102
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
90
103
  try {
@@ -96,7 +109,7 @@ async function publishDescriptor(resolved, descriptor) {
96
109
  if (!res.ok) {
97
110
  throw new PublishHttpError(res.status);
98
111
  }
99
- const ready = await waitForAdminReady(resolved.apiBaseUrl.replace(/\/$/, ""), headers);
112
+ const ready = await waitForAdminReady(trimTrailingSlashes(resolved.apiBaseUrl), headers);
100
113
  if (!ready) {
101
114
  console.warn("cms0: publish succeeded, but admin did not become healthy in time.");
102
115
  }
@@ -8,6 +8,12 @@ const primitive = (type) => ({
8
8
  const fileFieldDescriptors = {
9
9
  name: primitive("string"),
10
10
  filename: primitive("string"),
11
+ storageKey: {
12
+ kind: "primitive",
13
+ type: "string",
14
+ optional: true,
15
+ nullable: false,
16
+ },
11
17
  extension: primitive("string"),
12
18
  mimeType: primitive("string"),
13
19
  size: primitive("number"),