@fragno-dev/cloudflare-fragment 0.0.1

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 (64) hide show
  1. package/LICENSE.md +16 -0
  2. package/README.md +92 -0
  3. package/dist/browser/client/react.d.ts +290 -0
  4. package/dist/browser/client/react.d.ts.map +1 -0
  5. package/dist/browser/client/react.js +166 -0
  6. package/dist/browser/client/react.js.map +1 -0
  7. package/dist/browser/client/solid.d.ts +292 -0
  8. package/dist/browser/client/solid.d.ts.map +1 -0
  9. package/dist/browser/client/solid.js +136 -0
  10. package/dist/browser/client/solid.js.map +1 -0
  11. package/dist/browser/client/svelte.d.ts +287 -0
  12. package/dist/browser/client/svelte.d.ts.map +1 -0
  13. package/dist/browser/client/svelte.js +134 -0
  14. package/dist/browser/client/svelte.js.map +1 -0
  15. package/dist/browser/client/vanilla.d.ts +316 -0
  16. package/dist/browser/client/vanilla.d.ts.map +1 -0
  17. package/dist/browser/client/vanilla.js +160 -0
  18. package/dist/browser/client/vanilla.js.map +1 -0
  19. package/dist/browser/client/vue.d.ts +290 -0
  20. package/dist/browser/client/vue.d.ts.map +1 -0
  21. package/dist/browser/client/vue.js +133 -0
  22. package/dist/browser/client/vue.js.map +1 -0
  23. package/dist/browser/client-Bk-J98pf.d.ts +679 -0
  24. package/dist/browser/client-Bk-J98pf.d.ts.map +1 -0
  25. package/dist/browser/index.d.ts +2027 -0
  26. package/dist/browser/index.d.ts.map +1 -0
  27. package/dist/browser/index.js +27 -0
  28. package/dist/browser/index.js.map +1 -0
  29. package/dist/browser/schema-Bt-h9kGf.js +2348 -0
  30. package/dist/browser/schema-Bt-h9kGf.js.map +1 -0
  31. package/dist/node/cloudflare-api.d.ts +106 -0
  32. package/dist/node/cloudflare-api.d.ts.map +1 -0
  33. package/dist/node/cloudflare-api.js +146 -0
  34. package/dist/node/cloudflare-api.js.map +1 -0
  35. package/dist/node/contracts.d.ts +288 -0
  36. package/dist/node/contracts.d.ts.map +1 -0
  37. package/dist/node/contracts.js +66 -0
  38. package/dist/node/contracts.js.map +1 -0
  39. package/dist/node/definition.d.ts +339 -0
  40. package/dist/node/definition.d.ts.map +1 -0
  41. package/dist/node/definition.js +417 -0
  42. package/dist/node/definition.js.map +1 -0
  43. package/dist/node/deployment-tag.d.ts +13 -0
  44. package/dist/node/deployment-tag.d.ts.map +1 -0
  45. package/dist/node/deployment-tag.js +73 -0
  46. package/dist/node/deployment-tag.js.map +1 -0
  47. package/dist/node/index.d.ts +786 -0
  48. package/dist/node/index.d.ts.map +1 -0
  49. package/dist/node/index.js +35 -0
  50. package/dist/node/index.js.map +1 -0
  51. package/dist/node/routes.d.ts +520 -0
  52. package/dist/node/routes.d.ts.map +1 -0
  53. package/dist/node/routes.js +100 -0
  54. package/dist/node/routes.js.map +1 -0
  55. package/dist/node/schema.d.ts +11 -0
  56. package/dist/node/schema.d.ts.map +1 -0
  57. package/dist/node/schema.js +24 -0
  58. package/dist/node/schema.js.map +1 -0
  59. package/dist/node/script-name.d.ts +13 -0
  60. package/dist/node/script-name.d.ts.map +1 -0
  61. package/dist/node/script-name.js +35 -0
  62. package/dist/node/script-name.js.map +1 -0
  63. package/dist/tsconfig.tsbuildinfo +1 -0
  64. package/package.json +98 -0
@@ -0,0 +1,100 @@
1
+ import { SUPPORTED_DEPLOYMENT_FORMAT, cloudflareAppListSchema, cloudflareAppStateSchema, cloudflareDeployRequestSchema, cloudflareDeploymentDetailSchema, cloudflareDeploymentListSchema, cloudflareDeploymentSummarySchema } from "./contracts.js";
2
+ import { cloudflareFragmentDefinition } from "./definition.js";
3
+ import { defineRoutes } from "@fragno-dev/core";
4
+ import { ExponentialBackoffRetryPolicy } from "@fragno-dev/db";
5
+
6
+ //#region src/routes.ts
7
+ const writeRetryPolicy = new ExponentialBackoffRetryPolicy({
8
+ maxRetries: 5,
9
+ initialDelayMs: 10,
10
+ maxDelayMs: 250
11
+ });
12
+ const cloudflareRoutesFactory = defineRoutes(cloudflareFragmentDefinition).create(({ services, defineRoute }) => {
13
+ return [
14
+ defineRoute({
15
+ method: "GET",
16
+ path: "/apps",
17
+ outputSchema: cloudflareAppListSchema,
18
+ handler: async function(_input, { json }) {
19
+ const [apps] = await this.handlerTx().withServiceCalls(() => [services.listApps()]).execute();
20
+ return json({ apps });
21
+ }
22
+ }),
23
+ defineRoute({
24
+ method: "POST",
25
+ path: "/apps/:appId/deployments",
26
+ inputSchema: cloudflareDeployRequestSchema,
27
+ outputSchema: cloudflareDeploymentSummarySchema,
28
+ errorCodes: ["INVALID_DEPLOY_INPUT", "UNSUPPORTED_DEPLOY_REQUEST"],
29
+ handler: async function({ input, pathParams }, { json, error }) {
30
+ const payload = await input.valid();
31
+ if (payload.script.type !== SUPPORTED_DEPLOYMENT_FORMAT) return error({
32
+ message: "Only single-module ES module deployments are supported in the first slice.",
33
+ code: "UNSUPPORTED_DEPLOY_REQUEST"
34
+ }, 400);
35
+ if (payload.script.entrypoint.trim().length === 0) return error({
36
+ message: "Deployment entrypoint cannot be empty.",
37
+ code: "INVALID_DEPLOY_INPUT"
38
+ }, 400);
39
+ if (payload.script.content.trim().length === 0) return error({
40
+ message: "Deployment source cannot be empty.",
41
+ code: "INVALID_DEPLOY_INPUT"
42
+ }, 400);
43
+ const [deployment] = await this.handlerTx({ retryPolicy: writeRetryPolicy }).withServiceCalls(() => [services.queueDeployment(pathParams.appId, payload)]).execute();
44
+ return json(deployment);
45
+ }
46
+ }),
47
+ defineRoute({
48
+ method: "GET",
49
+ path: "/apps/:appId/deployments",
50
+ outputSchema: cloudflareDeploymentListSchema,
51
+ errorCodes: ["APP_NOT_FOUND"],
52
+ handler: async function({ pathParams }, { json, error }) {
53
+ const [deployments] = await this.handlerTx().withServiceCalls(() => [services.listAppDeployments(pathParams.appId)]).execute();
54
+ if (!deployments) return error({
55
+ message: `App '${pathParams.appId}' was not found.`,
56
+ code: "APP_NOT_FOUND"
57
+ }, 404);
58
+ return json({ deployments });
59
+ }
60
+ }),
61
+ defineRoute({
62
+ method: "GET",
63
+ path: "/deployments/:deploymentId",
64
+ outputSchema: cloudflareDeploymentDetailSchema,
65
+ errorCodes: ["DEPLOYMENT_NOT_FOUND"],
66
+ handler: async function({ pathParams }, { json, error }) {
67
+ const [deployment] = await this.handlerTx().withServiceCalls(() => [services.getDeployment(pathParams.deploymentId)]).execute();
68
+ if (!deployment) return error({
69
+ message: `Deployment '${pathParams.deploymentId}' was not found.`,
70
+ code: "DEPLOYMENT_NOT_FOUND"
71
+ }, 404);
72
+ return json(deployment);
73
+ }
74
+ }),
75
+ defineRoute({
76
+ method: "GET",
77
+ path: "/apps/:appId",
78
+ outputSchema: cloudflareAppStateSchema,
79
+ errorCodes: ["APP_NOT_FOUND"],
80
+ handler: async function({ pathParams }, { json, error }) {
81
+ const [app, deployments] = await this.handlerTx().withServiceCalls(() => [services.getAppState(pathParams.appId), services.listAppDeployments(pathParams.appId)]).execute();
82
+ if (!app || !deployments) return error({
83
+ message: `App '${pathParams.appId}' was not found.`,
84
+ code: "APP_NOT_FOUND"
85
+ }, 404);
86
+ const liveDeployment = app.liveDeploymentId ? deployments.find((deployment) => deployment.id === app.liveDeploymentId) ?? null : null;
87
+ return json({
88
+ ...app,
89
+ liveDeployment,
90
+ liveDeploymentError: null,
91
+ deployments
92
+ });
93
+ }
94
+ })
95
+ ];
96
+ });
97
+
98
+ //#endregion
99
+ export { cloudflareRoutesFactory };
100
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","names":[],"sources":["../../src/routes.ts"],"sourcesContent":["import { defineRoutes } from \"@fragno-dev/core\";\nimport { ExponentialBackoffRetryPolicy } from \"@fragno-dev/db\";\n\nimport {\n SUPPORTED_DEPLOYMENT_FORMAT,\n cloudflareAppListSchema,\n cloudflareAppStateSchema,\n cloudflareDeployRequestSchema,\n cloudflareDeploymentDetailSchema,\n cloudflareDeploymentListSchema,\n cloudflareDeploymentSummarySchema,\n} from \"./contracts\";\nimport { cloudflareFragmentDefinition } from \"./definition\";\n\nconst writeRetryPolicy = new ExponentialBackoffRetryPolicy({\n maxRetries: 5,\n initialDelayMs: 10,\n maxDelayMs: 250,\n});\n\nexport const cloudflareRoutesFactory = defineRoutes(cloudflareFragmentDefinition).create(\n ({ services, defineRoute }) => {\n return [\n defineRoute({\n method: \"GET\",\n path: \"/apps\",\n outputSchema: cloudflareAppListSchema,\n handler: async function (_input, { json }) {\n const [apps] = await this.handlerTx()\n .withServiceCalls(() => [services.listApps()])\n .execute();\n\n return json({ apps });\n },\n }),\n defineRoute({\n method: \"POST\",\n path: \"/apps/:appId/deployments\",\n inputSchema: cloudflareDeployRequestSchema,\n outputSchema: cloudflareDeploymentSummarySchema,\n errorCodes: [\"INVALID_DEPLOY_INPUT\", \"UNSUPPORTED_DEPLOY_REQUEST\"],\n handler: async function ({ input, pathParams }, { json, error }) {\n const payload = await input.valid();\n\n if (payload.script.type !== SUPPORTED_DEPLOYMENT_FORMAT) {\n return error(\n {\n message:\n \"Only single-module ES module deployments are supported in the first slice.\",\n code: \"UNSUPPORTED_DEPLOY_REQUEST\",\n },\n 400,\n );\n }\n\n if (payload.script.entrypoint.trim().length === 0) {\n return error(\n {\n message: \"Deployment entrypoint cannot be empty.\",\n code: \"INVALID_DEPLOY_INPUT\",\n },\n 400,\n );\n }\n\n if (payload.script.content.trim().length === 0) {\n return error(\n {\n message: \"Deployment source cannot be empty.\",\n code: \"INVALID_DEPLOY_INPUT\",\n },\n 400,\n );\n }\n\n const [deployment] = await this.handlerTx({ retryPolicy: writeRetryPolicy })\n .withServiceCalls(() => [services.queueDeployment(pathParams.appId, payload)])\n .execute();\n\n return json(deployment);\n },\n }),\n defineRoute({\n method: \"GET\",\n path: \"/apps/:appId/deployments\",\n outputSchema: cloudflareDeploymentListSchema,\n errorCodes: [\"APP_NOT_FOUND\"],\n handler: async function ({ pathParams }, { json, error }) {\n const [deployments] = await this.handlerTx()\n .withServiceCalls(() => [services.listAppDeployments(pathParams.appId)])\n .execute();\n\n if (!deployments) {\n return error(\n {\n message: `App '${pathParams.appId}' was not found.`,\n code: \"APP_NOT_FOUND\",\n },\n 404,\n );\n }\n\n return json({ deployments });\n },\n }),\n defineRoute({\n method: \"GET\",\n path: \"/deployments/:deploymentId\",\n outputSchema: cloudflareDeploymentDetailSchema,\n errorCodes: [\"DEPLOYMENT_NOT_FOUND\"],\n handler: async function ({ pathParams }, { json, error }) {\n const [deployment] = await this.handlerTx()\n .withServiceCalls(() => [services.getDeployment(pathParams.deploymentId)])\n .execute();\n\n if (!deployment) {\n return error(\n {\n message: `Deployment '${pathParams.deploymentId}' was not found.`,\n code: \"DEPLOYMENT_NOT_FOUND\",\n },\n 404,\n );\n }\n\n return json(deployment);\n },\n }),\n defineRoute({\n method: \"GET\",\n path: \"/apps/:appId\",\n outputSchema: cloudflareAppStateSchema,\n errorCodes: [\"APP_NOT_FOUND\"],\n handler: async function ({ pathParams }, { json, error }) {\n const [app, deployments] = await this.handlerTx()\n .withServiceCalls(\n () =>\n [\n services.getAppState(pathParams.appId),\n services.listAppDeployments(pathParams.appId),\n ] as const,\n )\n .execute();\n\n if (!app || !deployments) {\n return error(\n {\n message: `App '${pathParams.appId}' was not found.`,\n code: \"APP_NOT_FOUND\",\n },\n 404,\n );\n }\n\n const liveDeployment = app.liveDeploymentId\n ? (deployments.find((deployment) => deployment.id === app.liveDeploymentId) ?? null)\n : null;\n\n return json({\n ...app,\n liveDeployment,\n liveDeploymentError: null,\n deployments,\n });\n },\n }),\n ];\n },\n);\n"],"mappings":";;;;;;AAcA,MAAM,mBAAmB,IAAI,8BAA8B;CACzD,YAAY;CACZ,gBAAgB;CAChB,YAAY;CACb,CAAC;AAEF,MAAa,0BAA0B,aAAa,6BAA6B,CAAC,QAC/E,EAAE,UAAU,kBAAkB;AAC7B,QAAO;EACL,YAAY;GACV,QAAQ;GACR,MAAM;GACN,cAAc;GACd,SAAS,eAAgB,QAAQ,EAAE,QAAQ;IACzC,MAAM,CAAC,QAAQ,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uB;GACpC,SAAS,eAAgB,EAAE,cAAc,EAAE,MAAM,SAAS;IACxD,MAAM,CAAC,cAAc,MAAM,KAAK,WAAW,CACxC,uBAAuB,CAAC,SAAS,cAAc,WAAW,aAAa,CAAC,CAAC,CACzE,SAAS;AAEZ,QAAI,CAAC,WACH,QAAO,MACL;KACE,SAAS,eAAe,WAAW,aAAa;KAChD,MAAM;KACP,EACD,IACD;AAGH,WAAO,KAAK,WAAW;;GAE1B,CAAC;EACF,YAAY;GACV,QAAQ;GACR,MAAM;GACN,cAAc;GACd,YAAY,CAAC,gBAAgB;GAC7B,SAAS,eAAgB,EAAE,cAAc,EAAE,MAAM,SAAS;IACxD,MAAM,CAAC,KAAK,eAAe,MAAM,KAAK,WAAW,CAC9C,uBAEG,CACE,SAAS,YAAY,WAAW,MAAM,EACtC,SAAS,mBAAmB,WAAW,MAAM,CAC9C,CACJ,CACA,SAAS;AAEZ,QAAI,CAAC,OAAO,CAAC,YACX,QAAO,MACL;KACE,SAAS,QAAQ,WAAW,MAAM;KAClC,MAAM;KACP,EACD,IACD;IAGH,MAAM,iBAAiB,IAAI,mBACtB,YAAY,MAAM,eAAe,WAAW,OAAO,IAAI,iBAAiB,IAAI,OAC7E;AAEJ,WAAO,KAAK;KACV,GAAG;KACH;KACA,qBAAqB;KACrB;KACD,CAAC;;GAEL,CAAC;EACH;EAEJ"}
@@ -0,0 +1,11 @@
1
+ import * as _fragno_dev_db0 from "@fragno-dev/db";
2
+ import * as _fragno_dev_db_schema0 from "@fragno-dev/db/schema";
3
+
4
+ //#region src/schema.d.ts
5
+ declare const cloudflareSchema: _fragno_dev_db_schema0.Schema<{
6
+ app: _fragno_dev_db_schema0.Table<Record<"id", _fragno_dev_db_schema0.IdColumn<"varchar(128)", string | _fragno_dev_db_schema0.FragnoId | null, _fragno_dev_db_schema0.FragnoId>> & Record<"scriptName", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"liveDeploymentId", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"liveCloudflareEtag", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"firstDeploymentLeaseId", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"createdAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>> & Record<"updatedAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>>, Record<string, _fragno_dev_db_schema0.AnyRelation>, Record<string, _fragno_dev_db_schema0.Index<_fragno_dev_db_schema0.AnyColumn[], readonly string[]>> & Record<"idx_app_scriptName", _fragno_dev_db_schema0.Index<readonly [_fragno_dev_db_schema0.Column<"string", string, string>] & _fragno_dev_db_schema0.AnyColumn[], readonly ["scriptName"]>>>;
7
+ deployment: _fragno_dev_db_schema0.Table<Record<"id", _fragno_dev_db_schema0.IdColumn<"varchar(128)", string | _fragno_dev_db_schema0.FragnoId | null, _fragno_dev_db_schema0.FragnoId>> & Record<"appId", _fragno_dev_db_schema0.Column<"bigint", string | bigint | _fragno_dev_db_schema0.FragnoId | _fragno_dev_db_schema0.FragnoReference, _fragno_dev_db_schema0.FragnoReference>> & Record<"status", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"format", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"entrypoint", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"scriptName", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"sourceCode", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"sourceByteLength", _fragno_dev_db_schema0.Column<"integer", number, number>> & Record<"compatibilityDate", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"compatibilityFlags", _fragno_dev_db_schema0.Column<"json", unknown, unknown>> & Record<"attemptCount", _fragno_dev_db_schema0.Column<"integer", number | null, number>> & Record<"startedAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date | null>> & Record<"completedAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date | null>> & Record<"errorCode", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"errorMessage", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"cloudflareEtag", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"cloudflareModifiedOn", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"cloudflareResponse", _fragno_dev_db_schema0.Column<"json", unknown, unknown>> & Record<"createdAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>> & Record<"updatedAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>>, Record<string, _fragno_dev_db_schema0.AnyRelation> & Record<"app", _fragno_dev_db_schema0.Relation<"one", _fragno_dev_db_schema0.Table<Record<"id", _fragno_dev_db_schema0.IdColumn<"varchar(128)", string | _fragno_dev_db_schema0.FragnoId | null, _fragno_dev_db_schema0.FragnoId>> & Record<"scriptName", _fragno_dev_db_schema0.Column<"string", string, string>> & Record<"liveDeploymentId", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"liveCloudflareEtag", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"firstDeploymentLeaseId", _fragno_dev_db_schema0.Column<"string", string | null, string | null>> & Record<"createdAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>> & Record<"updatedAt", _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>>, Record<string, _fragno_dev_db_schema0.AnyRelation>, Record<string, _fragno_dev_db_schema0.Index<_fragno_dev_db_schema0.AnyColumn[], readonly string[]>> & Record<"idx_app_scriptName", _fragno_dev_db_schema0.Index<readonly [_fragno_dev_db_schema0.Column<"string", string, string>] & _fragno_dev_db_schema0.AnyColumn[], readonly ["scriptName"]>>>>>, Record<string, _fragno_dev_db_schema0.Index<_fragno_dev_db_schema0.AnyColumn[], readonly string[]>> & Record<"idx_deployment_app_createdAt", _fragno_dev_db_schema0.Index<readonly [_fragno_dev_db_schema0.Column<"bigint", string | bigint | _fragno_dev_db_schema0.FragnoId | _fragno_dev_db_schema0.FragnoReference, _fragno_dev_db_schema0.FragnoReference>, _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>] & _fragno_dev_db_schema0.AnyColumn[], readonly ["appId", "createdAt"]>> & Record<"idx_deployment_status_createdAt", _fragno_dev_db_schema0.Index<readonly [_fragno_dev_db_schema0.Column<"string", string, string>, _fragno_dev_db_schema0.Column<"timestamp", (Date | _fragno_dev_db0.DbNow) | null, Date>] & _fragno_dev_db_schema0.AnyColumn[], readonly ["status", "createdAt"]>>>;
8
+ }>;
9
+ //#endregion
10
+ export { cloudflareSchema };
11
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/schema.ts"],"mappings":";;;;cAEa,gBAAA,yBAAgB,MAAA;0GAuD3B,sBAAA,CAAA,QAAA"}
@@ -0,0 +1,24 @@
1
+ import { column, idColumn, referenceColumn, schema } from "@fragno-dev/db/schema";
2
+
3
+ //#region src/schema.ts
4
+ const cloudflareSchema = schema("cloudflare-fragment", (s) => {
5
+ return s.addTable("app", (t) => {
6
+ return t.addColumn("id", idColumn()).addColumn("scriptName", column("string")).addColumn("liveDeploymentId", column("string").nullable()).addColumn("liveCloudflareEtag", column("string").nullable()).addColumn("firstDeploymentLeaseId", column("string").nullable()).addColumn("createdAt", column("timestamp").defaultTo((b) => b.now())).addColumn("updatedAt", column("timestamp").defaultTo((b) => b.now())).createIndex("idx_app_scriptName", ["scriptName"], { unique: true });
7
+ }).addTable("deployment", (t) => {
8
+ return t.addColumn("id", idColumn()).addColumn("appId", referenceColumn()).addColumn("status", column("string")).addColumn("format", column("string")).addColumn("entrypoint", column("string")).addColumn("scriptName", column("string")).addColumn("sourceCode", column("string")).addColumn("sourceByteLength", column("integer")).addColumn("compatibilityDate", column("string")).addColumn("compatibilityFlags", column("json")).addColumn("attemptCount", column("integer").defaultTo(0)).addColumn("startedAt", column("timestamp").nullable()).addColumn("completedAt", column("timestamp").nullable()).addColumn("errorCode", column("string").nullable()).addColumn("errorMessage", column("string").nullable()).addColumn("cloudflareEtag", column("string").nullable()).addColumn("cloudflareModifiedOn", column("string").nullable()).addColumn("cloudflareResponse", column("json").nullable()).addColumn("createdAt", column("timestamp").defaultTo((b) => b.now())).addColumn("updatedAt", column("timestamp").defaultTo((b) => b.now())).createIndex("idx_deployment_app_createdAt", ["appId", "createdAt"]).createIndex("idx_deployment_status_createdAt", ["status", "createdAt"]);
9
+ }).addReference("app", {
10
+ type: "one",
11
+ from: {
12
+ table: "deployment",
13
+ column: "appId"
14
+ },
15
+ to: {
16
+ table: "app",
17
+ column: "id"
18
+ }
19
+ });
20
+ });
21
+
22
+ //#endregion
23
+ export { cloudflareSchema };
24
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/schema.ts"],"sourcesContent":["import { column, idColumn, referenceColumn, schema } from \"@fragno-dev/db/schema\";\n\nexport const cloudflareSchema = schema(\"cloudflare-fragment\", (s) => {\n return s\n .addTable(\"app\", (t) => {\n return t\n .addColumn(\"id\", idColumn())\n .addColumn(\"scriptName\", column(\"string\"))\n .addColumn(\"liveDeploymentId\", column(\"string\").nullable())\n .addColumn(\"liveCloudflareEtag\", column(\"string\").nullable())\n .addColumn(\"firstDeploymentLeaseId\", column(\"string\").nullable())\n .addColumn(\n \"createdAt\",\n column(\"timestamp\").defaultTo((b) => b.now()),\n )\n .addColumn(\n \"updatedAt\",\n column(\"timestamp\").defaultTo((b) => b.now()),\n )\n .createIndex(\"idx_app_scriptName\", [\"scriptName\"], { unique: true });\n })\n .addTable(\"deployment\", (t) => {\n return t\n .addColumn(\"id\", idColumn())\n .addColumn(\"appId\", referenceColumn())\n .addColumn(\"status\", column(\"string\"))\n .addColumn(\"format\", column(\"string\"))\n .addColumn(\"entrypoint\", column(\"string\"))\n .addColumn(\"scriptName\", column(\"string\"))\n .addColumn(\"sourceCode\", column(\"string\"))\n .addColumn(\"sourceByteLength\", column(\"integer\"))\n .addColumn(\"compatibilityDate\", column(\"string\"))\n .addColumn(\"compatibilityFlags\", column(\"json\"))\n .addColumn(\"attemptCount\", column(\"integer\").defaultTo(0))\n .addColumn(\"startedAt\", column(\"timestamp\").nullable())\n .addColumn(\"completedAt\", column(\"timestamp\").nullable())\n .addColumn(\"errorCode\", column(\"string\").nullable())\n .addColumn(\"errorMessage\", column(\"string\").nullable())\n .addColumn(\"cloudflareEtag\", column(\"string\").nullable())\n .addColumn(\"cloudflareModifiedOn\", column(\"string\").nullable())\n .addColumn(\"cloudflareResponse\", column(\"json\").nullable())\n .addColumn(\n \"createdAt\",\n column(\"timestamp\").defaultTo((b) => b.now()),\n )\n .addColumn(\n \"updatedAt\",\n column(\"timestamp\").defaultTo((b) => b.now()),\n )\n .createIndex(\"idx_deployment_app_createdAt\", [\"appId\", \"createdAt\"])\n .createIndex(\"idx_deployment_status_createdAt\", [\"status\", \"createdAt\"]);\n })\n .addReference(\"app\", {\n type: \"one\",\n from: { table: \"deployment\", column: \"appId\" },\n to: { table: \"app\", column: \"id\" },\n });\n});\n"],"mappings":";;;AAEA,MAAa,mBAAmB,OAAO,wBAAwB,MAAM;AACnE,QAAO,EACJ,SAAS,QAAQ,MAAM;AACtB,SAAO,EACJ,UAAU,MAAM,UAAU,CAAC,CAC3B,UAAU,cAAc,OAAO,SAAS,CAAC,CACzC,UAAU,oBAAoB,OAAO,SAAS,CAAC,UAAU,CAAC,CAC1D,UAAU,sBAAsB,OAAO,SAAS,CAAC,UAAU,CAAC,CAC5D,UAAU,0BAA0B,OAAO,SAAS,CAAC,UAAU,CAAC,CAChE,UACC,aACA,OAAO,YAAY,CAAC,WAAW,MAAM,EAAE,KAAK,CAAC,CAC9C,CACA,UACC,aAC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AS;EAC9C,IAAI;GAAE,OAAO;GAAO,QAAQ;GAAM;EACnC,CAAC;EACJ"}
@@ -0,0 +1,13 @@
1
+ //#region src/script-name.d.ts
2
+ interface CloudflareScriptNameConfig {
3
+ scriptNamePrefix?: string;
4
+ scriptNameSuffix?: string;
5
+ scriptNameSeparator?: string;
6
+ maxScriptNameLength?: number;
7
+ }
8
+ declare const DEFAULT_SCRIPT_NAME_SEPARATOR = "-";
9
+ declare const DEFAULT_MAX_SCRIPT_NAME_LENGTH = 63;
10
+ declare const resolveCloudflareScriptName: (appId: string, config?: CloudflareScriptNameConfig) => string;
11
+ //#endregion
12
+ export { CloudflareScriptNameConfig, DEFAULT_MAX_SCRIPT_NAME_LENGTH, DEFAULT_SCRIPT_NAME_SEPARATOR, resolveCloudflareScriptName };
13
+ //# sourceMappingURL=script-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-name.d.ts","names":[],"sources":["../../src/script-name.ts"],"mappings":";UAAiB,0BAAA;EACf,gBAAA;EACA,gBAAA;EACA,mBAAA;EACA,mBAAA;AAAA;AAAA,cAGW,6BAAA;AAAA,cACA,8BAAA;AAAA,cA2BA,2BAAA,GACX,KAAA,UACA,MAAA,GAAQ,0BAAA"}
@@ -0,0 +1,35 @@
1
+ //#region src/script-name.ts
2
+ const DEFAULT_SCRIPT_NAME_SEPARATOR = "-";
3
+ const DEFAULT_MAX_SCRIPT_NAME_LENGTH = 63;
4
+ const normalizeSeparator = (value) => {
5
+ const cleaned = (value ?? DEFAULT_SCRIPT_NAME_SEPARATOR).replace(/[^a-z0-9-]+/gi, "-");
6
+ return cleaned.length > 0 ? cleaned : DEFAULT_SCRIPT_NAME_SEPARATOR;
7
+ };
8
+ const sanitizeSegment = (value) => {
9
+ return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+/, "").replace(/-+$/, "").replace(/-{2,}/g, "-");
10
+ };
11
+ const hashString = (value) => {
12
+ let hash = 2166136261;
13
+ for (const char of value) {
14
+ hash ^= char.charCodeAt(0);
15
+ hash = Math.imul(hash, 16777619);
16
+ }
17
+ return (hash >>> 0).toString(16).padStart(8, "0");
18
+ };
19
+ const resolveCloudflareScriptName = (appId, config = {}) => {
20
+ const separator = normalizeSeparator(config.scriptNameSeparator);
21
+ const maxLength = Math.max(16, config.maxScriptNameLength ?? DEFAULT_MAX_SCRIPT_NAME_LENGTH);
22
+ const base = [
23
+ config.scriptNamePrefix,
24
+ appId,
25
+ config.scriptNameSuffix
26
+ ].map((segment) => sanitizeSegment(segment ?? "")).filter(Boolean).join(separator) || "app";
27
+ if (base.length <= maxLength) return base;
28
+ const hash = hashString(base);
29
+ const budget = Math.max(1, maxLength - hash.length - separator.length);
30
+ return `${base.slice(0, budget).replace(/-+$/, "") || "app"}${separator}${hash}`.slice(0, maxLength).replace(/-+$/, "");
31
+ };
32
+
33
+ //#endregion
34
+ export { DEFAULT_MAX_SCRIPT_NAME_LENGTH, DEFAULT_SCRIPT_NAME_SEPARATOR, resolveCloudflareScriptName };
35
+ //# sourceMappingURL=script-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-name.js","names":[],"sources":["../../src/script-name.ts"],"sourcesContent":["export interface CloudflareScriptNameConfig {\n scriptNamePrefix?: string;\n scriptNameSuffix?: string;\n scriptNameSeparator?: string;\n maxScriptNameLength?: number;\n}\n\nexport const DEFAULT_SCRIPT_NAME_SEPARATOR = \"-\";\nexport const DEFAULT_MAX_SCRIPT_NAME_LENGTH = 63;\n\nconst normalizeSeparator = (value?: string) => {\n const cleaned = (value ?? DEFAULT_SCRIPT_NAME_SEPARATOR).replace(/[^a-z0-9-]+/gi, \"-\");\n return cleaned.length > 0 ? cleaned : DEFAULT_SCRIPT_NAME_SEPARATOR;\n};\n\nconst sanitizeSegment = (value: string) => {\n return value\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+/, \"\")\n .replace(/-+$/, \"\")\n .replace(/-{2,}/g, \"-\");\n};\n\nconst hashString = (value: string) => {\n let hash = 2166136261;\n\n for (const char of value) {\n hash ^= char.charCodeAt(0);\n hash = Math.imul(hash, 16777619);\n }\n\n return (hash >>> 0).toString(16).padStart(8, \"0\");\n};\n\nexport const resolveCloudflareScriptName = (\n appId: string,\n config: CloudflareScriptNameConfig = {},\n) => {\n const separator = normalizeSeparator(config.scriptNameSeparator);\n const maxLength = Math.max(16, config.maxScriptNameLength ?? DEFAULT_MAX_SCRIPT_NAME_LENGTH);\n const segments = [config.scriptNamePrefix, appId, config.scriptNameSuffix]\n .map((segment) => sanitizeSegment(segment ?? \"\"))\n .filter(Boolean);\n const base = segments.join(separator) || \"app\";\n\n if (base.length <= maxLength) {\n return base;\n }\n\n const hash = hashString(base);\n const budget = Math.max(1, maxLength - hash.length - separator.length);\n const trimmedBase = base.slice(0, budget).replace(/-+$/, \"\") || \"app\";\n const candidate = `${trimmedBase}${separator}${hash}`;\n\n return candidate.slice(0, maxLength).replace(/-+$/, \"\");\n};\n"],"mappings":";AAOA,MAAa,gCAAgC;AAC7C,MAAa,iCAAiC;AAE9C,MAAM,sBAAsB,UAAmB;CAC7C,MAAM,WAAW,SAAS,+BAA+B,QAAQ,iBAAiB,IAAI;AACtF,QAAO,QAAQ,SAAS,IAAI,UAAU;;AAGxC,MAAM,mBAAmB,UAAkB;AACzC,QAAO,MACJ,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,OAAO,GAAG,CAClB,QAAQ,OAAO,GAAG,CAClB,QAAQ,UAAU,IAAI;;AAG3B,MAAM,cAAc,UAAkB;CACpC,IAAI,OAAO;AAEX,MAAK,MAAM,QAAQ,OAAO;AACxB,UAAQ,KAAK,WAAW,EAAE;AAC1B,SAAO,KAAK,KAAK,MAAM,SAAS;;AAGlC,SAAQ,SAAS,GAAG,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI;;AAGnD,MAAa,+BACX,OACA,SAAqC,EAAE,KACpC;CACH,MAAM,YAAY,mBAAmB,OAAO,oBAAoB;CAChE,MAAM,YAAY,KAAK,IAAI,IAAI,OAAO,uBAAuB,+BAA+B;CAI5F,MAAM,OAHW;EAAC,OAAO;EAAkB;EAAO,OAAO;EAAiB,CACvE,KAAK,YAAY,gBAAgB,WAAW,GAAG,CAAC,CAChD,OAAO,QAAQ,CACI,KAAK,UAAU,IAAI;AAEzC,KAAI,KAAK,UAAU,UACjB,QAAO;CAGT,MAAM,OAAO,WAAW,KAAK;CAC7B,MAAM,SAAS,KAAK,IAAI,GAAG,YAAY,KAAK,SAAS,UAAU,OAAO;AAItE,QAFkB,GADE,KAAK,MAAM,GAAG,OAAO,CAAC,QAAQ,OAAO,GAAG,IAAI,QAC7B,YAAY,OAE9B,MAAM,GAAG,UAAU,CAAC,QAAQ,OAAO,GAAG"}