@pithy-sh/cloudflare 0.9.1 → 0.9.2

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 +1 @@
1
- {"version":3,"file":"d1PreparedStatement.d.ts","sourceRoot":"","sources":["../../src/d1/d1PreparedStatement.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,mBAAmB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA6B7C;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB;aAAK,UAAU,EAAE,CAAC;CAAW,CAAC;AAY3D,qBAAa,uBAAuB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,YAAW,mBAAmB;IAC9F,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAY;IAExC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IAEpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,YAAY,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,OAAO,EAAO,EAM9G;IAED,gGAAgG;IAChG,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAErD;IAED,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjC;IAED,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjC;IAEK,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,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AO,EAM9G;IAED,gGAAgG;IAChG,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAErD;IAED,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjC;IAED,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEjC;IAEK,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACvD,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IASlC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,OAAO,EAAE;QAAE,WAAW,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAChF,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;YAmB5D,YAAY;CAgB3B"}
@@ -36,10 +36,15 @@ function mapMeta(restMeta) {
36
36
  * surfaces as the timeout it was, and `cloudflareRequest` already tells the operator to check before retrying.
37
37
  */
38
38
  const D1_QUERY_REQUEST = { maxRetries: 0 };
39
- /** The REST `params` array is strings; coerce each bound value the way the D1 REST API expects. */
40
- function toStringParams(params) {
39
+ /**
40
+ * Encode each bound value for the REST `params` array: a string as itself, a number or boolean as its
41
+ * string, and a null as JSON `null`, which D1 binds as SQL NULL. `""` would bind as text, and a nullable
42
+ * column would hold a value no reader takes for absent. Numbers stay strings because a JSON number binds
43
+ * as `real`, and the column's affinity converts the string.
44
+ */
45
+ function toRestParams(params) {
41
46
  return params.map((value) => {
42
- if (value === null || value === void 0) return "";
47
+ if (value === null || value === void 0) return null;
43
48
  if (typeof value === "string") return value;
44
49
  if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
45
50
  return JSON.stringify(value);
@@ -75,7 +80,7 @@ var D1PreparedStatementREST = class D1PreparedStatementREST {
75
80
  return row;
76
81
  }
77
82
  async raw(options) {
78
- const params = this.boundParams.length > 0 ? toStringParams(this.boundParams) : void 0;
83
+ const params = this.boundParams.length > 0 ? toRestParams(this.boundParams) : void 0;
79
84
  const rawResult = (await cloudflareRequest("D1 raw query", () => this.client.d1.database.raw(this.databaseId, {
80
85
  account_id: this.accountId,
81
86
  sql: this.sql,
@@ -86,7 +91,7 @@ var D1PreparedStatementREST = class D1PreparedStatementREST {
86
91
  return rows;
87
92
  }
88
93
  async executeQuery() {
89
- const params = this.boundParams.length > 0 ? toStringParams(this.boundParams) : void 0;
94
+ const params = this.boundParams.length > 0 ? toRestParams(this.boundParams) : void 0;
90
95
  const queryResult = (await cloudflareRequest("D1 query", () => this.client.d1.database.query(this.databaseId, {
91
96
  account_id: this.accountId,
92
97
  sql: this.sql,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/cloudflare",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "js-base64": "^3.9.2"
41
41
  },
42
42
  "peerDependencies": {
43
- "@pithy-sh/core": "^0.16.0",
43
+ "@pithy-sh/core": "^0.16.1",
44
44
  "zod": "^4.4.0"
45
45
  },
46
46
  "devDependencies": {
@@ -42,14 +42,21 @@ function mapMeta(restMeta?: QueryResult.Meta): D1Meta & Record<string, unknown>
42
42
  */
43
43
  export const D1_QUERY_REQUEST = { maxRetries: 0 } as const;
44
44
 
45
- /** The REST `params` array is strings; coerce each bound value the way the D1 REST API expects. */
46
- function toStringParams(params: unknown[]): string[] {
47
- return params.map((value) => {
48
- if (value === null || value === undefined) return "";
45
+ /**
46
+ * Encode each bound value for the REST `params` array: a string as itself, a number or boolean as its
47
+ * string, and a null as JSON `null`, which D1 binds as SQL NULL. `""` would bind as text, and a nullable
48
+ * column would hold a value no reader takes for absent. Numbers stay strings because a JSON number binds
49
+ * as `real`, and the column's affinity converts the string.
50
+ */
51
+ function toRestParams(params: unknown[]): string[] {
52
+ const encoded = params.map((value): string | null => {
53
+ if (value === null || value === undefined) return null;
49
54
  if (typeof value === "string") return value;
50
55
  if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
51
56
  return JSON.stringify(value);
52
57
  });
58
+ // The SDK types `params` as strings only; the API takes a null in the array.
59
+ return encoded as string[];
53
60
  }
54
61
 
55
62
  export class D1PreparedStatementREST<T = Record<string, unknown>> implements D1PreparedStatement {
@@ -97,7 +104,7 @@ export class D1PreparedStatementREST<T = Record<string, unknown>> implements D1P
97
104
  async raw<U = unknown[]>(options: { columnNames: true }): Promise<[string[], ...U[]]>;
98
105
  async raw<U = unknown[]>(options?: { columnNames?: false }): Promise<U[]>;
99
106
  async raw<U = unknown[]>(options?: { columnNames?: boolean }): Promise<U[] | [string[], ...U[]]> {
100
- const params = this.boundParams.length > 0 ? toStringParams(this.boundParams) : undefined;
107
+ const params = this.boundParams.length > 0 ? toRestParams(this.boundParams) : undefined;
101
108
  const response = await cloudflareRequest("D1 raw query", () =>
102
109
  this.client.d1.database.raw(
103
110
  this.databaseId,
@@ -115,7 +122,7 @@ export class D1PreparedStatementREST<T = Record<string, unknown>> implements D1P
115
122
  }
116
123
 
117
124
  private async executeQuery<U>(): Promise<D1Result<U>> {
118
- const params = this.boundParams.length > 0 ? toStringParams(this.boundParams) : undefined;
125
+ const params = this.boundParams.length > 0 ? toRestParams(this.boundParams) : undefined;
119
126
  const response = await cloudflareRequest("D1 query", () =>
120
127
  this.client.d1.database.query(
121
128
  this.databaseId,