@base44-preview/cli 0.1.1-pr.555.6305311 → 0.1.1-pr.555.77b65cb

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/cli/index.js CHANGED
@@ -243758,8 +243758,9 @@ var RealtimeHandlerConfigSchema = exports_external.object({
243758
243758
  entry: exports_external.string().min(1)
243759
243759
  });
243760
243760
  var RealtimeHandlerSchemaFileSchema = exports_external.object({
243761
- inbound: exports_external.unknown().optional(),
243762
- outbound: exports_external.unknown().optional()
243761
+ types: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
243762
+ toClient: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
243763
+ toServer: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
243763
243764
  });
243764
243765
  var DeployRealtimeHandlerResponseSchema = exports_external.object({
243765
243766
  status: exports_external.enum(["deployed", "unchanged"]),
@@ -243777,7 +243778,7 @@ async function deploySingleRealtimeHandler(name2, payload) {
243777
243778
  const appClient = getAppClient();
243778
243779
  let response;
243779
243780
  try {
243780
- response = await appClient.put(`backend-functions/${encodeURIComponent(name2)}`, { json: payload, timeout: false });
243781
+ response = await appClient.put(`realtime-handlers/${encodeURIComponent(name2)}`, { json: payload, timeout: false });
243781
243782
  } catch (error48) {
243782
243783
  throw await ApiError.fromHttpError(error48, `deploying realtime handler "${name2}"`);
243783
243784
  }
@@ -243813,8 +243814,9 @@ async function readRealtimeHandler(entryFile, realtimeDir) {
243813
243814
  const result = RealtimeHandlerSchemaFileSchema.safeParse(parsed);
243814
243815
  if (result.success) {
243815
243816
  messageSchema = {
243816
- inbound: result.data.inbound,
243817
- outbound: result.data.outbound
243817
+ types: result.data.types,
243818
+ toClient: result.data.toClient,
243819
+ toServer: result.data.toServer
243818
243820
  };
243819
243821
  }
243820
243822
  }
@@ -254717,7 +254719,7 @@ async function generateContent(input) {
254717
254719
  if (!entities.length && !functions.length && !agents.length && !connectors.length && !realtimeHandlers.length) {
254718
254720
  return EMPTY_TEMPLATE;
254719
254721
  }
254720
- const [entityInterfaces, realtimeRegistryEntries] = await Promise.all([
254722
+ const [entityInterfaces, realtimeResults] = await Promise.all([
254721
254723
  Promise.all(entities.map((e8) => compileEntity(e8))),
254722
254724
  Promise.all(realtimeHandlers.map((h5) => compileRealtimeHandler(h5)))
254723
254725
  ]);
@@ -254735,18 +254737,22 @@ async function generateContent(input) {
254735
254737
  ],
254736
254738
  [
254737
254739
  "RealtimeHandlerRegistry",
254738
- realtimeHandlers.filter((h5) => h5.messageSchema).map((h5, _10, _arr) => {
254740
+ realtimeHandlers.filter((h5) => h5.messageSchema).map((h5) => {
254739
254741
  const idx = realtimeHandlers.indexOf(h5);
254740
- return `"${h5.name}": ${realtimeRegistryEntries[idx]};`;
254742
+ return `"${h5.name}": ${realtimeResults[idx].entry};`;
254741
254743
  })
254742
254744
  ]
254743
254745
  ];
254744
254746
  const registries2 = registryEntries.filter(([, entries]) => entries.length > 0).map(([name2, entries]) => registry2(name2, entries));
254747
+ const realtimeInterfaces = realtimeResults.map((r5) => r5.decls).filter(Boolean);
254745
254748
  return [
254746
254749
  HEADER2,
254747
254750
  "export {};",
254748
254751
  entityInterfaces.join(`
254749
254752
 
254753
+ `),
254754
+ realtimeInterfaces.join(`
254755
+
254750
254756
  `),
254751
254757
  import_common_tags.source`
254752
254758
  declare module '${sdkPackage}' {
@@ -254779,29 +254785,75 @@ async function compileEntity(entity2) {
254779
254785
  }
254780
254786
  async function compileRealtimeHandler(handler) {
254781
254787
  const { messageSchema } = handler;
254782
- if (!messageSchema)
254783
- return "{ inbound: unknown; outbound: unknown }";
254784
- const compileSchema = async (schema11, typeName) => {
254785
- if (!schema11)
254786
- return "unknown";
254787
- try {
254788
- const ts8 = await import_json_schema_to_typescript.compile(schema11, typeName, {
254789
- bannerComment: "",
254790
- additionalProperties: false,
254791
- strictIndexSignatures: true
254792
- });
254793
- const match = ts8.match(/\{([\s\S]*)\}/);
254794
- return match ? `{
254795
- ${match[1]}}` : "unknown";
254796
- } catch {
254797
- return "unknown";
254798
- }
254788
+ if (!messageSchema) {
254789
+ return { decls: "", entry: "{ toClient: unknown; toServer: unknown }" };
254790
+ }
254791
+ const prefix = toPascalCase(handler.name);
254792
+ const types = messageSchema.types ?? {};
254793
+ const toClient = messageSchema.toClient ?? {};
254794
+ const toServer = messageSchema.toServer ?? {};
254795
+ const typeName = (key2) => `${prefix}${toPascalCase(key2)}`;
254796
+ const msgName = (dir, key2) => `${prefix}${dir}${toPascalCase(key2)}`;
254797
+ const defs = {};
254798
+ const add = (name2, schema11) => {
254799
+ if (name2 in defs) {
254800
+ throw new TypeGenerationError(`Duplicate generated type "${name2}" in realtime handler "${handler.name}" — a shared type and a message resolve to the same name.`, handler.name);
254801
+ }
254802
+ defs[name2] = { ...schema11, title: name2 };
254803
+ };
254804
+ for (const [key2, schema11] of Object.entries(types)) {
254805
+ add(typeName(key2), rewriteTypeRefs(schema11, typeName));
254806
+ }
254807
+ const compileMessages = (msgs, dir) => Object.entries(msgs).map(([key2, schema11]) => {
254808
+ const name2 = msgName(dir, key2);
254809
+ const rewritten = rewriteTypeRefs(schema11, typeName);
254810
+ add(name2, {
254811
+ type: "object",
254812
+ ...rewritten,
254813
+ properties: { type: { const: key2 }, ...rewritten.properties ?? {} },
254814
+ required: ["type", ...rewritten.required ?? []],
254815
+ additionalProperties: false
254816
+ });
254817
+ return name2;
254818
+ });
254819
+ const toClientNames = compileMessages(toClient, "ToClient");
254820
+ const toServerNames = compileMessages(toServer, "ToServer");
254821
+ const allNames = [...toClientNames, ...toServerNames];
254822
+ const rootName = `${prefix}Message`;
254823
+ const rootSchema = {
254824
+ title: rootName,
254825
+ $defs: defs,
254826
+ oneOf: allNames.map((n5) => ({ $ref: `#/$defs/${n5}` }))
254799
254827
  };
254800
- const [inbound, outbound] = await Promise.all([
254801
- compileSchema(messageSchema.inbound, `${handler.name}Inbound`),
254802
- compileSchema(messageSchema.outbound, `${handler.name}Outbound`)
254803
- ]);
254804
- return `{ inbound: ${inbound}; outbound: ${outbound} }`;
254828
+ let decls = "";
254829
+ try {
254830
+ decls = (await import_json_schema_to_typescript.compile(rootSchema, rootName, {
254831
+ bannerComment: "",
254832
+ additionalProperties: false,
254833
+ strictIndexSignatures: true
254834
+ })).trim();
254835
+ } catch (error48) {
254836
+ throw new TypeGenerationError(`Failed to generate types for realtime handler "${handler.name}"`, handler.name, error48);
254837
+ }
254838
+ const union2 = (names) => names.length ? names.join(" | ") : "never";
254839
+ return {
254840
+ decls,
254841
+ entry: `{ toClient: ${union2(toClientNames)}; toServer: ${union2(toServerNames)} }`
254842
+ };
254843
+ }
254844
+ function rewriteTypeRefs(node, defName) {
254845
+ if (Array.isArray(node)) {
254846
+ return node.map((n5) => rewriteTypeRefs(n5, defName));
254847
+ }
254848
+ if (node && typeof node === "object") {
254849
+ const out = {};
254850
+ for (const [key2, value] of Object.entries(node)) {
254851
+ const match = key2 === "$ref" && typeof value === "string" ? value.match(/^#\/types\/(.+)$/) : null;
254852
+ out[key2] = match ? `#/$defs/${defName(match[1])}` : rewriteTypeRefs(value, defName);
254853
+ }
254854
+ return out;
254855
+ }
254856
+ return node;
254805
254857
  }
254806
254858
  function registry2(name2, entries) {
254807
254859
  return import_common_tags.source`
@@ -262896,4 +262948,4 @@ export {
262896
262948
  CLIExitError
262897
262949
  };
262898
262950
 
262899
- //# debugId=8333EEB4A43A09C964756E2164756E21
262951
+ //# debugId=89497C2C2C3F39A664756E2164756E21