@kyro-cms/core 0.9.7 → 0.9.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.
Files changed (101) hide show
  1. package/dist/{WebhookService-BKszZlG0.d.cts → WebhookService-Dj8pJ3sp.d.cts} +1 -1
  2. package/dist/{WebhookService-Ccf1j-IN.d.ts → WebhookService-DpRB940h.d.ts} +1 -1
  3. package/dist/api-handler-graphql.cjs +18 -13
  4. package/dist/api-handler-graphql.cjs.map +1 -1
  5. package/dist/api-handler-graphql.js +14 -9
  6. package/dist/api-handler-graphql.js.map +1 -1
  7. package/dist/api-handler-trpc.cjs +9 -9
  8. package/dist/api-handler-trpc.js +7 -7
  9. package/dist/api-handler.cjs +10 -10
  10. package/dist/api-handler.js +7 -7
  11. package/dist/{base-CIuXkrH4.d.cts → base-BjyoF6da.d.cts} +2 -2
  12. package/dist/{base-fFo4lqER.d.ts → base-C2YR8lWt.d.ts} +2 -2
  13. package/dist/{chunk-NZEUU7QB.js → chunk-3AKCVYDB.js} +4 -109
  14. package/dist/chunk-3AKCVYDB.js.map +1 -0
  15. package/dist/{chunk-FKKQUMXR.cjs → chunk-4OCMVGEY.cjs} +4 -110
  16. package/dist/chunk-4OCMVGEY.cjs.map +1 -0
  17. package/dist/{chunk-VLK5SJRI.js → chunk-5RFGYEQ3.js} +133 -46
  18. package/dist/chunk-5RFGYEQ3.js.map +1 -0
  19. package/dist/chunk-5RPRLTTN.js +861 -0
  20. package/dist/chunk-5RPRLTTN.js.map +1 -0
  21. package/dist/{chunk-AX2TZRQJ.js → chunk-BVUDFKKS.js} +16 -3
  22. package/dist/chunk-BVUDFKKS.js.map +1 -0
  23. package/dist/{chunk-DRVOUQMT.cjs → chunk-E4JZ73FY.cjs} +54 -79
  24. package/dist/chunk-E4JZ73FY.cjs.map +1 -0
  25. package/dist/{chunk-E5UJBLQ7.js → chunk-FIAMXNTH.js} +2 -2
  26. package/dist/chunk-FIAMXNTH.js.map +1 -0
  27. package/dist/{chunk-QVJNSAQL.cjs → chunk-IEIHABVR.cjs} +152 -65
  28. package/dist/chunk-IEIHABVR.cjs.map +1 -0
  29. package/dist/{chunk-QFLB4EIJ.cjs → chunk-LNTFRAHF.cjs} +118 -9
  30. package/dist/chunk-LNTFRAHF.cjs.map +1 -0
  31. package/dist/chunk-N4GN6Q3V.cjs +869 -0
  32. package/dist/chunk-N4GN6Q3V.cjs.map +1 -0
  33. package/dist/{chunk-FSKONGCX.cjs → chunk-OJ2AM75W.cjs} +2 -2
  34. package/dist/chunk-OJ2AM75W.cjs.map +1 -0
  35. package/dist/{chunk-QX3WNQ7V.js → chunk-OX6GOIPH.js} +4 -4
  36. package/dist/{chunk-QX3WNQ7V.js.map → chunk-OX6GOIPH.js.map} +1 -1
  37. package/dist/{chunk-OZ3CCTTA.cjs → chunk-OXYSOU6Z.cjs} +18 -5
  38. package/dist/chunk-OXYSOU6Z.cjs.map +1 -0
  39. package/dist/{chunk-CMXVTUYV.js → chunk-OYCICW4B.js} +38 -63
  40. package/dist/chunk-OYCICW4B.js.map +1 -0
  41. package/dist/{chunk-HVCUIII2.cjs → chunk-TQG7G7YI.cjs} +13 -13
  42. package/dist/{chunk-HVCUIII2.cjs.map → chunk-TQG7G7YI.cjs.map} +1 -1
  43. package/dist/{chunk-3UK5XBVJ.js → chunk-WDTTHKDS.js} +117 -10
  44. package/dist/chunk-WDTTHKDS.js.map +1 -0
  45. package/dist/cli/index.cjs +148 -14
  46. package/dist/cli/index.cjs.map +1 -1
  47. package/dist/cli/index.js +148 -14
  48. package/dist/cli/index.js.map +1 -1
  49. package/dist/client.cjs +3 -3
  50. package/dist/client.d.cts +2 -2
  51. package/dist/client.d.ts +2 -2
  52. package/dist/client.js +1 -1
  53. package/dist/drizzle/index.d.cts +3 -3
  54. package/dist/drizzle/index.d.ts +3 -3
  55. package/dist/fields/index.cjs +21 -21
  56. package/dist/fields/index.d.cts +1 -1
  57. package/dist/fields/index.d.ts +1 -1
  58. package/dist/fields/index.js +1 -1
  59. package/dist/graphql/index.cjs +13 -5
  60. package/dist/graphql/index.d.cts +37 -7
  61. package/dist/graphql/index.d.ts +37 -7
  62. package/dist/graphql/index.js +2 -2
  63. package/dist/{index-BKta3cBH.d.cts → index-DHbywDs-.d.cts} +2 -2
  64. package/dist/{index-ClOqnkTO.d.ts → index-jLs0zlft.d.ts} +2 -2
  65. package/dist/index.cjs +90 -90
  66. package/dist/index.d.cts +15 -14
  67. package/dist/index.d.ts +15 -14
  68. package/dist/index.js +8 -8
  69. package/dist/mongodb/index.d.cts +3 -3
  70. package/dist/mongodb/index.d.ts +3 -3
  71. package/dist/rest/index.cjs +5 -5
  72. package/dist/rest/index.d.cts +4 -4
  73. package/dist/rest/index.d.ts +4 -4
  74. package/dist/rest/index.js +3 -3
  75. package/dist/templates/index.d.cts +2 -2
  76. package/dist/templates/index.d.ts +2 -2
  77. package/dist/trpc/index.cjs +12 -12
  78. package/dist/trpc/index.d.cts +3 -3
  79. package/dist/trpc/index.d.ts +3 -3
  80. package/dist/trpc/index.js +3 -3
  81. package/dist/{types-Dgzlftb7.d.ts → types-BzH3_rtP.d.ts} +7 -7
  82. package/dist/{types-Ds0tCA3L.d.cts → types-CY_iNunL.d.cts} +7 -7
  83. package/dist/{types-DeSApf9T.d.ts → types-C_rVxU2T.d.cts} +4 -4
  84. package/dist/{types-DeSApf9T.d.cts → types-C_rVxU2T.d.ts} +4 -4
  85. package/package.json +2 -1
  86. package/dist/chunk-3UK5XBVJ.js.map +0 -1
  87. package/dist/chunk-AX2TZRQJ.js.map +0 -1
  88. package/dist/chunk-CMXVTUYV.js.map +0 -1
  89. package/dist/chunk-DRVOUQMT.cjs.map +0 -1
  90. package/dist/chunk-E5UJBLQ7.js.map +0 -1
  91. package/dist/chunk-FKKQUMXR.cjs.map +0 -1
  92. package/dist/chunk-FSKONGCX.cjs.map +0 -1
  93. package/dist/chunk-NZEUU7QB.js.map +0 -1
  94. package/dist/chunk-OZ3CCTTA.cjs.map +0 -1
  95. package/dist/chunk-PONTBXR5.js +0 -842
  96. package/dist/chunk-PONTBXR5.js.map +0 -1
  97. package/dist/chunk-QFLB4EIJ.cjs.map +0 -1
  98. package/dist/chunk-QVJNSAQL.cjs.map +0 -1
  99. package/dist/chunk-RRKCIAPU.cjs +0 -848
  100. package/dist/chunk-RRKCIAPU.cjs.map +0 -1
  101. package/dist/chunk-VLK5SJRI.js.map +0 -1
@@ -1,13 +1,15 @@
1
1
  import { createStorageSettingsGlobal } from './chunk-GAOXD3XT.js';
2
- import { createContext, createKyroServer } from './chunk-QX3WNQ7V.js';
3
- import { buildGraphQLSchema } from './chunk-PONTBXR5.js';
4
- import { getDefaultRegistry, createHonoApp, createS3Storage, createCloudinaryStorage, createFtpStorage } from './chunk-VLK5SJRI.js';
5
- import { createWebhookService, WEBHOOK_COLLECTION, WEBHOOK_DELIVERY_COLLECTION } from './chunk-3UK5XBVJ.js';
6
- import { API_KEY_COLLECTION, extractApiKeyFromRequest, validateApiKey, createApiKeyContext } from './chunk-NZEUU7QB.js';
2
+ import { createContext, createKyroServer } from './chunk-OX6GOIPH.js';
3
+ import { buildGraphQLSchema, RelationLoader } from './chunk-5RPRLTTN.js';
4
+ import { getDefaultRegistry, createHonoApp, createS3Storage, createCloudinaryStorage, createFtpStorage } from './chunk-5RFGYEQ3.js';
5
+ import { createWebhookService, WEBHOOK_COLLECTION, WEBHOOK_DELIVERY_COLLECTION } from './chunk-WDTTHKDS.js';
6
+ import { API_KEY_COLLECTION, extractApiKeyFromRequest, validateApiKey, createApiKeyContext } from './chunk-3AKCVYDB.js';
7
7
  import { KyroPubSub, createWSServer } from './chunk-BYBMTIMT.js';
8
+ import { DrizzleAdapter } from './chunk-V7KZQIZ6.js';
9
+ import { apiKeys } from './chunk-UUDTPZX6.js';
8
10
  import { AbstractBaseAdapter, applyRLS, DEFAULT_RLS_CONFIG, canAccessDocument } from './chunk-WXVB364T.js';
9
11
  import { z } from 'zod';
10
- import { parse, execute } from 'graphql';
12
+ import { createYoga } from 'graphql-yoga';
11
13
  import { createRequire } from 'module';
12
14
  import { randomBytes } from 'crypto';
13
15
 
@@ -1553,6 +1555,13 @@ var Kyro = class {
1553
1555
  ]
1554
1556
  };
1555
1557
  const allGlobals = this.registry.getGlobals();
1558
+ if (this.db instanceof DrizzleAdapter && this.db.dialect === "postgres") {
1559
+ const drizzle = this.db;
1560
+ const tableName = API_KEY_COLLECTION.replace(/-/g, "_");
1561
+ if (!drizzle.schema[tableName]) {
1562
+ drizzle.schema[tableName] = apiKeys;
1563
+ }
1564
+ }
1556
1565
  await this.db.init(
1557
1566
  [
1558
1567
  ...this.registry.getCollections(),
@@ -1624,78 +1633,41 @@ var Kyro = class {
1624
1633
  });
1625
1634
  }
1626
1635
  getGraphQL(options) {
1627
- const defaultSchema = buildGraphQLSchema({
1636
+ const schema = buildGraphQLSchema({
1628
1637
  registry: this.registry,
1629
1638
  db: this.db,
1630
- settings: this.settings,
1631
- user: options?.user,
1632
- req: options?.req,
1633
- tenantID: options?.tenantID
1639
+ settings: this.settings
1634
1640
  });
1635
- return {
1636
- fetch: async (request, _locals) => {
1641
+ const yoga = createYoga({
1642
+ schema,
1643
+ context: async ({ request }) => {
1637
1644
  const apiKeyRaw = extractApiKeyFromRequest(request);
1638
1645
  let gqlUser;
1639
1646
  let apiKeyCtx;
1640
1647
  if (apiKeyRaw && this.db) {
1641
1648
  const apiKeyResult = await validateApiKey(apiKeyRaw, this.db);
1642
- if (!apiKeyResult.valid) {
1643
- return new Response(
1644
- JSON.stringify({ errors: [{ message: apiKeyResult.error || "Invalid API key" }] }),
1645
- { status: 401, headers: { "Content-Type": "application/json" } }
1646
- );
1647
- }
1648
1649
  if (apiKeyResult.user) {
1649
1650
  gqlUser = apiKeyResult.user;
1650
1651
  apiKeyCtx = createApiKeyContext(apiKeyResult);
1651
1652
  }
1652
1653
  }
1653
- const mustRebuild = gqlUser !== options?.user || apiKeyCtx !== void 0;
1654
- const schema = mustRebuild ? buildGraphQLSchema({
1655
- registry: this.registry,
1654
+ const tenantID = options?.tenantID;
1655
+ return {
1656
1656
  db: this.db,
1657
- settings: this.settings,
1657
+ registry: this.registry,
1658
1658
  user: gqlUser,
1659
1659
  req: request,
1660
- tenantID: options?.tenantID,
1661
- apiKey: apiKeyCtx
1662
- }) : defaultSchema;
1663
- const body = request.method === "POST" ? await request.json().catch(() => ({})) : {};
1664
- const query = body.query || "";
1665
- const variables = body.variables || {};
1666
- if (!query) {
1667
- return new Response(
1668
- JSON.stringify({ error: "No GraphQL query provided" }),
1669
- { status: 400, headers: { "Content-Type": "application/json" } }
1670
- );
1671
- }
1672
- try {
1673
- const document = parse(query);
1674
- const result = await execute({
1675
- schema,
1676
- document,
1677
- variableValues: variables,
1678
- contextValue: {
1679
- db: this.db,
1680
- registry: this.registry,
1681
- settings: this.settings,
1682
- user: gqlUser,
1683
- req: request,
1684
- tenantID: options?.tenantID
1685
- }
1686
- });
1687
- return new Response(JSON.stringify(result), {
1688
- status: 200,
1689
- headers: { "Content-Type": "application/json" }
1690
- });
1691
- } catch (err) {
1692
- return new Response(
1693
- JSON.stringify({ errors: [{ message: err.message }] }),
1694
- { status: 400, headers: { "Content-Type": "application/json" } }
1695
- );
1696
- }
1660
+ tenantID,
1661
+ apiKey: apiKeyCtx,
1662
+ relationLoader: new RelationLoader({ db: this.db, tenantID, user: gqlUser })
1663
+ };
1697
1664
  },
1698
- schema: defaultSchema
1665
+ graphiql: false,
1666
+ plugins: []
1667
+ });
1668
+ return {
1669
+ fetch: yoga.fetch,
1670
+ schema
1699
1671
  };
1700
1672
  }
1701
1673
  getTRPC(options) {
@@ -2290,6 +2262,7 @@ var LocalAdapter = class extends AbstractBaseAdapter {
2290
2262
  this.db.prepare(
2291
2263
  `INSERT OR REPLACE INTO ${tableName} (${quotedColumns.join(", ")}) VALUES (${placeholders})`
2292
2264
  ).run(...values);
2265
+ this.ensureVersionsTable();
2293
2266
  return this.findByID({ collection: slug, id, tenantID, draft: true });
2294
2267
  }
2295
2268
  async update(args) {
@@ -2319,6 +2292,7 @@ var LocalAdapter = class extends AbstractBaseAdapter {
2319
2292
  params.push(tenantID);
2320
2293
  }
2321
2294
  this.db.prepare(sql).run(...params);
2295
+ this.ensureVersionsTable();
2322
2296
  return this.findByID({ collection: slug, id, tenantID, draft: true });
2323
2297
  }
2324
2298
  async delete(args) {
@@ -2326,6 +2300,7 @@ var LocalAdapter = class extends AbstractBaseAdapter {
2326
2300
  const parsed = this.parseGlobalsSlug(slug);
2327
2301
  const config = parsed.isGlobal ? this.globals.get(parsed.globalSlug) : this.getCollection(slug);
2328
2302
  this.ensureTable(config, parsed.tableName);
2303
+ this.ensureVersionsTable();
2329
2304
  const doc = await this.findByID({ collection: slug, id, tenantID, draft: true });
2330
2305
  if (!doc) throw new Error(`Document not found: ${slug}/${id}`);
2331
2306
  const tableName = parsed.tableName;
@@ -2762,5 +2737,5 @@ function createLocalAdapter(options) {
2762
2737
  }
2763
2738
 
2764
2739
  export { ConfigValidationError, Kyro, LocalAdapter, Registry, collectionToCreateZod, collectionToUpdateZod, collectionToWhereZod, collectionToZod, createKyro, createLocalAdapter, createRegistry, fieldToZod, getRegistry, globalToZod, resetRegistry, validateCollection, validateConfig, validateFields, validateGlobal };
2765
- //# sourceMappingURL=chunk-CMXVTUYV.js.map
2766
- //# sourceMappingURL=chunk-CMXVTUYV.js.map
2740
+ //# sourceMappingURL=chunk-OYCICW4B.js.map
2741
+ //# sourceMappingURL=chunk-OYCICW4B.js.map