@cms0/cms0 0.0.7 → 0.0.9

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.
@@ -1,8 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.cms0 = cms0;
4
37
  const schema_descriptors_1 = require("@cms0/cms0/schema-descriptors");
5
- const shared_1 = require("@cms0/shared");
38
+ const Shared = __importStar(require("@cms0/shared"));
6
39
  /**
7
40
  * Initializes the CMS SDK for a given schema.
8
41
  * @param config configuration including API base URL or database URL.
@@ -11,7 +44,6 @@ const shared_1 = require("@cms0/shared");
11
44
  function cms0(config) {
12
45
  const baseUrl = config.apiConfig?.baseUrl?.replace(/\/$/, "") ?? "";
13
46
  const apiKey = config.apiConfig?.key;
14
- console.log("apiKey: ", apiKey);
15
47
  return new Proxy({}, {
16
48
  get(target, prop) {
17
49
  if (!(prop in schema_descriptors_1.schemaDescriptor.roots)) {
@@ -31,7 +63,7 @@ function cms0(config) {
31
63
  }
32
64
  const data = await res.json();
33
65
  // Validate via Zod
34
- const { zodSchemas } = (0, shared_1.buildZodSchemasFromDescriptor)(schema_descriptors_1.schemaDescriptor);
66
+ const { zodSchemas } = Shared.buildZodSchemasFromDescriptor(schema_descriptors_1.schemaDescriptor);
35
67
  const schema = zodSchemas[prop];
36
68
  if (!schema) {
37
69
  // If no schema found, return the raw data
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildOnce = buildOnce;
4
4
  // Single-shot build that compiles the descriptor, writes it, and publishes it.
5
5
  const descriptor_builder_alt_js_1 = require("./descriptor-builder-alt.cjs");
6
- const paths_js_1 = require("./paths.cjs");
7
6
  const publisher_js_1 = require("./publisher.cjs");
8
7
  const descriptor_writer_js_1 = require("./descriptor-writer.cjs");
9
8
  function buildOnce(resolved) {
10
9
  const descriptor = (0, descriptor_builder_alt_js_1.buildDescriptorAlt)(resolved);
11
- (0, descriptor_writer_js_1.writeDescriptorFile)(descriptor, paths_js_1.descriptorOutPath);
10
+ (0, descriptor_writer_js_1.writeDescriptorFiles)(descriptor);
12
11
  (0, publisher_js_1.publishDescriptor)(resolved, descriptor);
13
12
  return descriptor;
14
13
  }
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeDescriptorFile = writeDescriptorFile;
6
+ exports.writeDescriptorFiles = writeDescriptorFiles;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
- function writeDescriptorFile(descriptor, outputPath) {
10
- const output = `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)} as const;\n`;
9
+ const paths_js_1 = require("./paths.cjs");
10
+ function safeWrite(outputPath, output) {
11
11
  try {
12
12
  fs_1.default.mkdirSync(path_1.default.dirname(outputPath), { recursive: true });
13
13
  fs_1.default.writeFileSync(outputPath, output, "utf8");
@@ -21,3 +21,19 @@ function writeDescriptorFile(descriptor, outputPath) {
21
21
  }
22
22
  }
23
23
  }
24
+ function createSourceTsOutput(descriptor) {
25
+ return `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)} as const;\n`;
26
+ }
27
+ function createEsmOutput(descriptor) {
28
+ return `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)};\n`;
29
+ }
30
+ function createCjsOutput(descriptor) {
31
+ return `// Auto-generated schema descriptor\nexports.schemaDescriptor = ${JSON.stringify(descriptor, null, 2)};\n`;
32
+ }
33
+ function writeDescriptorFiles(descriptor) {
34
+ if (fs_1.default.existsSync(path_1.default.resolve(path_1.default.dirname(paths_js_1.descriptorOutputPaths.sourceTs), ".."))) {
35
+ safeWrite(paths_js_1.descriptorOutputPaths.sourceTs, createSourceTsOutput(descriptor));
36
+ }
37
+ safeWrite(paths_js_1.descriptorOutputPaths.esmJs, createEsmOutput(descriptor));
38
+ safeWrite(paths_js_1.descriptorOutputPaths.cjsJs, createCjsOutput(descriptor));
39
+ }
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.packageRoot = exports.descriptorOutPath = void 0;
6
+ exports.packageRoot = exports.descriptorOutputPaths = void 0;
7
7
  // Path utilities for locating package-relative outputs.
8
8
  const path_1 = __importDefault(require("path"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
9
10
  const url_1 = require("url");
10
11
  const importMetaUrl = (() => {
11
12
  try {
@@ -22,7 +23,33 @@ const here = typeof __dirname === "string"
22
23
  : importMetaUrl
23
24
  ? path_1.default.dirname((0, url_1.fileURLToPath)(importMetaUrl))
24
25
  : process.cwd();
25
- const packageRoot = path_1.default.resolve(here, "../../..");
26
+ function findPackageRoot(startDir) {
27
+ let current = startDir;
28
+ while (true) {
29
+ const pkgPath = path_1.default.join(current, "package.json");
30
+ if (node_fs_1.default.existsSync(pkgPath)) {
31
+ try {
32
+ const pkg = JSON.parse(node_fs_1.default.readFileSync(pkgPath, "utf8"));
33
+ if (pkg.name === "@cms0/cms0") {
34
+ return current;
35
+ }
36
+ }
37
+ catch {
38
+ // Keep walking up if package.json cannot be parsed.
39
+ }
40
+ }
41
+ const parent = path_1.default.dirname(current);
42
+ if (parent === current)
43
+ break;
44
+ current = parent;
45
+ }
46
+ return path_1.default.resolve(startDir, "../../..");
47
+ }
48
+ const packageRoot = findPackageRoot(here);
26
49
  exports.packageRoot = packageRoot;
27
- const descriptorOutPath = path_1.default.resolve(packageRoot, "src/generated/schema-descriptor.ts");
28
- exports.descriptorOutPath = descriptorOutPath;
50
+ const descriptorOutputPaths = {
51
+ sourceTs: path_1.default.resolve(packageRoot, "src/generated/schema-descriptor.ts"),
52
+ esmJs: path_1.default.resolve(packageRoot, "dist/esm/generated/schema-descriptor.js"),
53
+ cjsJs: path_1.default.resolve(packageRoot, "dist/cjs/generated/schema-descriptor.cjs"),
54
+ };
55
+ exports.descriptorOutputPaths = descriptorOutputPaths;
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { schemaDescriptor } from "@cms0/cms0/schema-descriptors";
2
- import { buildZodSchemasFromDescriptor } from "@cms0/shared";
2
+ import * as Shared from "@cms0/shared";
3
3
  /**
4
4
  * Initializes the CMS SDK for a given schema.
5
5
  * @param config configuration including API base URL or database URL.
@@ -8,7 +8,6 @@ import { buildZodSchemasFromDescriptor } from "@cms0/shared";
8
8
  export function cms0(config) {
9
9
  const baseUrl = config.apiConfig?.baseUrl?.replace(/\/$/, "") ?? "";
10
10
  const apiKey = config.apiConfig?.key;
11
- console.log("apiKey: ", apiKey);
12
11
  return new Proxy({}, {
13
12
  get(target, prop) {
14
13
  if (!(prop in schemaDescriptor.roots)) {
@@ -28,7 +27,7 @@ export function cms0(config) {
28
27
  }
29
28
  const data = await res.json();
30
29
  // Validate via Zod
31
- const { zodSchemas } = buildZodSchemasFromDescriptor(schemaDescriptor);
30
+ const { zodSchemas } = Shared.buildZodSchemasFromDescriptor(schemaDescriptor);
32
31
  const schema = zodSchemas[prop];
33
32
  if (!schema) {
34
33
  // If no schema found, return the raw data
@@ -1,11 +1,10 @@
1
1
  // Single-shot build that compiles the descriptor, writes it, and publishes it.
2
2
  import { buildDescriptorAlt as buildDescriptor } from "./descriptor-builder-alt.js";
3
- import { descriptorOutPath } from "./paths.js";
4
3
  import { publishDescriptor } from "./publisher.js";
5
- import { writeDescriptorFile } from "./descriptor-writer.js";
4
+ import { writeDescriptorFiles } from "./descriptor-writer.js";
6
5
  function buildOnce(resolved) {
7
6
  const descriptor = buildDescriptor(resolved);
8
- writeDescriptorFile(descriptor, descriptorOutPath);
7
+ writeDescriptorFiles(descriptor);
9
8
  publishDescriptor(resolved, descriptor);
10
9
  return descriptor;
11
10
  }
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- function writeDescriptorFile(descriptor, outputPath) {
4
- const output = `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)} as const;\n`;
3
+ import { descriptorOutputPaths } from "./paths.js";
4
+ function safeWrite(outputPath, output) {
5
5
  try {
6
6
  fs.mkdirSync(path.dirname(outputPath), { recursive: true });
7
7
  fs.writeFileSync(outputPath, output, "utf8");
@@ -15,4 +15,20 @@ function writeDescriptorFile(descriptor, outputPath) {
15
15
  }
16
16
  }
17
17
  }
18
- export { writeDescriptorFile };
18
+ function createSourceTsOutput(descriptor) {
19
+ return `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)} as const;\n`;
20
+ }
21
+ function createEsmOutput(descriptor) {
22
+ return `// Auto-generated schema descriptor\nexport const schemaDescriptor = ${JSON.stringify(descriptor, null, 2)};\n`;
23
+ }
24
+ function createCjsOutput(descriptor) {
25
+ return `// Auto-generated schema descriptor\nexports.schemaDescriptor = ${JSON.stringify(descriptor, null, 2)};\n`;
26
+ }
27
+ function writeDescriptorFiles(descriptor) {
28
+ if (fs.existsSync(path.resolve(path.dirname(descriptorOutputPaths.sourceTs), ".."))) {
29
+ safeWrite(descriptorOutputPaths.sourceTs, createSourceTsOutput(descriptor));
30
+ }
31
+ safeWrite(descriptorOutputPaths.esmJs, createEsmOutput(descriptor));
32
+ safeWrite(descriptorOutputPaths.cjsJs, createCjsOutput(descriptor));
33
+ }
34
+ export { writeDescriptorFiles };
@@ -1,5 +1,6 @@
1
1
  // Path utilities for locating package-relative outputs.
2
2
  import path from "path";
3
+ import fs from "node:fs";
3
4
  import { fileURLToPath } from "url";
4
5
  const importMetaUrl = (() => {
5
6
  try {
@@ -16,6 +17,32 @@ const here = typeof __dirname === "string"
16
17
  : importMetaUrl
17
18
  ? path.dirname(fileURLToPath(importMetaUrl))
18
19
  : process.cwd();
19
- const packageRoot = path.resolve(here, "../../..");
20
- const descriptorOutPath = path.resolve(packageRoot, "src/generated/schema-descriptor.ts");
21
- export { descriptorOutPath, packageRoot };
20
+ function findPackageRoot(startDir) {
21
+ let current = startDir;
22
+ while (true) {
23
+ const pkgPath = path.join(current, "package.json");
24
+ if (fs.existsSync(pkgPath)) {
25
+ try {
26
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
27
+ if (pkg.name === "@cms0/cms0") {
28
+ return current;
29
+ }
30
+ }
31
+ catch {
32
+ // Keep walking up if package.json cannot be parsed.
33
+ }
34
+ }
35
+ const parent = path.dirname(current);
36
+ if (parent === current)
37
+ break;
38
+ current = parent;
39
+ }
40
+ return path.resolve(startDir, "../../..");
41
+ }
42
+ const packageRoot = findPackageRoot(here);
43
+ const descriptorOutputPaths = {
44
+ sourceTs: path.resolve(packageRoot, "src/generated/schema-descriptor.ts"),
45
+ esmJs: path.resolve(packageRoot, "dist/esm/generated/schema-descriptor.js"),
46
+ cjsJs: path.resolve(packageRoot, "dist/cjs/generated/schema-descriptor.cjs"),
47
+ };
48
+ export { descriptorOutputPaths, packageRoot };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;KAC/B,CAAC,IAAI,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,CAoDrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKlD,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;KAC/B,CAAC,IAAI,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,CAkDrE"}
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/build.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,iBAAS,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAK3D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/build.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,iBAAS,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAK3D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { FullDescriptor } from "@cms0/shared";
2
- declare function writeDescriptorFile(descriptor: FullDescriptor, outputPath: string): void;
3
- export { writeDescriptorFile };
2
+ declare function writeDescriptorFiles(descriptor: FullDescriptor): void;
3
+ export { writeDescriptorFiles };
4
4
  //# sourceMappingURL=descriptor-writer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"descriptor-writer.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/descriptor-writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAI9C,iBAAS,mBAAmB,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,QAkB1E;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"descriptor-writer.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/descriptor-writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA4C9C,iBAAS,oBAAoB,CAAC,UAAU,EAAE,cAAc,QAMvD;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,4 +1,8 @@
1
1
  declare const packageRoot: string;
2
- declare const descriptorOutPath: string;
3
- export { descriptorOutPath, packageRoot };
2
+ declare const descriptorOutputPaths: {
3
+ sourceTs: string;
4
+ esmJs: string;
5
+ cjsJs: string;
6
+ };
7
+ export { descriptorOutputPaths, packageRoot };
4
8
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/paths.ts"],"names":[],"mappings":"AAqBA,QAAA,MAAM,WAAW,QAAiC,CAAC;AAEnD,QAAA,MAAM,iBAAiB,QAGtB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../../src/libs/cli/paths.ts"],"names":[],"mappings":"AA+CA,QAAA,MAAM,WAAW,QAAwB,CAAC;AAE1C,QAAA,MAAM,qBAAqB;;;;CAO1B,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cms0/cms0",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
@@ -57,7 +57,7 @@
57
57
  "ts-node": "^10.9.2",
58
58
  "typescript": "^5.9.3",
59
59
  "zod": "^4.1.12",
60
- "@cms0/shared": "0.0.4"
60
+ "@cms0/shared": "0.0.5"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/lodash": "^4.17.21",