@bagelink/sdk 0.0.1288 → 0.0.1292

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.cjs CHANGED
@@ -49,7 +49,7 @@ function schemaToType(schema) {
49
49
  return "undefined";
50
50
  case "null":
51
51
  return "null";
52
- case void 0:
52
+ case undefined:
53
53
  return "any";
54
54
  default:
55
55
  console.log("Unknown type", schema.type);
@@ -61,7 +61,7 @@ function isOptional(schema) {
61
61
  const splitType = type.split(/\s+\|\s+/);
62
62
  const includesNull = splitType.includes("null");
63
63
  const includesUndefined = splitType.includes("undefined");
64
- return includesNull || includesUndefined || schema.default !== void 0;
64
+ return includesNull || includesUndefined || schema.default !== undefined;
65
65
  }
66
66
  function cleanOptionals(str) {
67
67
  return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
@@ -343,7 +343,7 @@ function generateFunctions(paths, baseUrl) {
343
343
  }, body);
344
344
  }
345
345
  for (const [parent, object] of Object.entries(body)) {
346
- tsString += `export const ${parent} = ${JSON.stringify(object, void 0, 2)};
346
+ tsString += `export const ${parent} = ${JSON.stringify(object, undefined, 2)};
347
347
  `;
348
348
  }
349
349
  Object.entries(functionsInventory).forEach(([key, value]) => {
@@ -365,8 +365,16 @@ function generateTypes(schemas) {
365
365
  `;
366
366
  }
367
367
  if (!schema.properties) {
368
+ if (schema.additionalProperties === true) {
369
+ return `export type ${typeName} = { [key: string]: any };
370
+ `;
371
+ }
368
372
  return "";
369
373
  }
374
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
375
+ return `export type ${typeName} = { [key: string]: any };
376
+ `;
377
+ }
370
378
  const properties = Object.entries(schema.properties).map(([key, value]) => {
371
379
  const varType = formatVarType({ varName: key, schema: value });
372
380
  return ` ${varType}`;
@@ -460,7 +468,7 @@ class DataRequest {
460
468
  } catch (err) {
461
469
  console.log(err);
462
470
  this.bagel.onError?.(err);
463
- return void 0;
471
+ return undefined;
464
472
  }
465
473
  }
466
474
  item(id) {
@@ -497,7 +505,7 @@ class BagelAuth {
497
505
  this.bagel = bagel;
498
506
  this.bagel = bagel;
499
507
  }
500
- user = void 0;
508
+ user = undefined;
501
509
  async validateUser() {
502
510
  try {
503
511
  const { data: usr } = await axios.get("/users/me", {
@@ -545,7 +553,7 @@ class BagelAuth {
545
553
  this.bagel.onError?.(err);
546
554
  console.log(err);
547
555
  }
548
- this.user = void 0;
556
+ this.user = undefined;
549
557
  }
550
558
  async acceptInvite(token, user) {
551
559
  await axios.post(`/auth/accept-invite/${token}`, user);
@@ -575,7 +583,7 @@ class Bagel {
575
583
  axios.defaults.baseURL = this.host;
576
584
  this.onError = onError;
577
585
  }
578
- read_table = void 0;
586
+ read_table = undefined;
579
587
  data(table) {
580
588
  return new DataRequest(table, this);
581
589
  }
package/dist/index.mjs CHANGED
@@ -43,7 +43,7 @@ function schemaToType(schema) {
43
43
  return "undefined";
44
44
  case "null":
45
45
  return "null";
46
- case void 0:
46
+ case undefined:
47
47
  return "any";
48
48
  default:
49
49
  console.log("Unknown type", schema.type);
@@ -55,7 +55,7 @@ function isOptional(schema) {
55
55
  const splitType = type.split(/\s+\|\s+/);
56
56
  const includesNull = splitType.includes("null");
57
57
  const includesUndefined = splitType.includes("undefined");
58
- return includesNull || includesUndefined || schema.default !== void 0;
58
+ return includesNull || includesUndefined || schema.default !== undefined;
59
59
  }
60
60
  function cleanOptionals(str) {
61
61
  return str.split(" | ").filter((t) => t !== "null" && t !== "undefined").join(" | ");
@@ -337,7 +337,7 @@ function generateFunctions(paths, baseUrl) {
337
337
  }, body);
338
338
  }
339
339
  for (const [parent, object] of Object.entries(body)) {
340
- tsString += `export const ${parent} = ${JSON.stringify(object, void 0, 2)};
340
+ tsString += `export const ${parent} = ${JSON.stringify(object, undefined, 2)};
341
341
  `;
342
342
  }
343
343
  Object.entries(functionsInventory).forEach(([key, value]) => {
@@ -359,8 +359,16 @@ function generateTypes(schemas) {
359
359
  `;
360
360
  }
361
361
  if (!schema.properties) {
362
+ if (schema.additionalProperties === true) {
363
+ return `export type ${typeName} = { [key: string]: any };
364
+ `;
365
+ }
362
366
  return "";
363
367
  }
368
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
369
+ return `export type ${typeName} = { [key: string]: any };
370
+ `;
371
+ }
364
372
  const properties = Object.entries(schema.properties).map(([key, value]) => {
365
373
  const varType = formatVarType({ varName: key, schema: value });
366
374
  return ` ${varType}`;
@@ -454,7 +462,7 @@ class DataRequest {
454
462
  } catch (err) {
455
463
  console.log(err);
456
464
  this.bagel.onError?.(err);
457
- return void 0;
465
+ return undefined;
458
466
  }
459
467
  }
460
468
  item(id) {
@@ -491,7 +499,7 @@ class BagelAuth {
491
499
  this.bagel = bagel;
492
500
  this.bagel = bagel;
493
501
  }
494
- user = void 0;
502
+ user = undefined;
495
503
  async validateUser() {
496
504
  try {
497
505
  const { data: usr } = await axios.get("/users/me", {
@@ -539,7 +547,7 @@ class BagelAuth {
539
547
  this.bagel.onError?.(err);
540
548
  console.log(err);
541
549
  }
542
- this.user = void 0;
550
+ this.user = undefined;
543
551
  }
544
552
  async acceptInvite(token, user) {
545
553
  await axios.post(`/auth/accept-invite/${token}`, user);
@@ -569,7 +577,7 @@ class Bagel {
569
577
  axios.defaults.baseURL = this.host;
570
578
  this.onError = onError;
571
579
  }
572
- read_table = void 0;
580
+ read_table = undefined;
573
581
  data(table) {
574
582
  return new DataRequest(table, this);
575
583
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1288",
4
+ "version": "0.0.1292",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -51,6 +51,7 @@ export interface SchemaObject {
51
51
  description?: string
52
52
  default?: any
53
53
  required?: string[]
54
+ additionalProperties?: boolean | SchemaObject
54
55
  }
55
56
 
56
57
  export interface ParameterObject {
@@ -19,15 +19,23 @@ export function generateTypes(schemas: SchemasObject): string {
19
19
  // }
20
20
 
21
21
  if (!schema.properties) {
22
+ // Handle case where schema has additionalProperties: true
23
+ if (schema.additionalProperties === true) {
24
+ return `export type ${typeName} = { [key: string]: any };\n`
25
+ }
22
26
  // #region Debug
23
27
  // console.log('No properties found for schema:', typeName)
24
-
25
28
  // console.log(JSON.stringify({ typeName, schema }, null, 2))
26
29
  // #endregion Debug
27
30
 
28
31
  return ''
29
32
  }
30
33
 
34
+ // Handle empty properties with additionalProperties
35
+ if (Object.keys(schema.properties).length === 0 && schema.additionalProperties === true) {
36
+ return `export type ${typeName} = { [key: string]: any };\n`
37
+ }
38
+
31
39
  const properties = Object.entries(schema.properties)
32
40
  .map(([key, value]) => {
33
41
  const varType = formatVarType({ varName: key, schema: value })