@rexezuge/d1 1.0.6 → 1.0.8
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/D1Retry.d.ts.map +1 -1
- package/dist/D1Retry.js.map +1 -1
- package/dist/aes-gcm.d.ts.map +1 -1
- package/dist/aes-gcm.js +14 -1
- package/dist/aes-gcm.js.map +1 -1
- package/dist/splitSql.d.ts.map +1 -1
- package/dist/splitSql.js +1 -3
- package/dist/splitSql.js.map +1 -1
- package/package.json +3 -3
package/dist/D1Retry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D1Retry.d.ts","sourceRoot":"","sources":["../src/D1Retry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAgB1C;;;;GAIG;AACH,QAAA,MAAM,iBAAiB;;;CAAmF,CAAC;AAE3G,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,iBAAS,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExC;AAED;;;;;GAKG;AACH,iBAAS,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/D;AAMD;;;;;;;;;;;;;GAaG;AACH,iBAAe,gBAAgB,CAAC,CAAC,SAAS,QAAQ,
|
|
1
|
+
{"version":3,"file":"D1Retry.d.ts","sourceRoot":"","sources":["../src/D1Retry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAgB1C;;;;GAIG;AACH,QAAA,MAAM,iBAAiB;;;CAAmF,CAAC;AAE3G,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,iBAA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IAED,uEAAuE;IACvE,4EAA4E;IAC5E,+BAA+B;IAC/B,MAAM,IAAI,aAAa,CAAC,aAAa,OAAO,UAAU,UAAU,GAAG,CAAC,WAAW,CAAC,CAAC;AACnF,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC","sourcesContent":["import { DatabaseError } from '@rexezuge/errors';\nimport { isD1ErrorRetryable } from './D1ErrorClassifier';\nimport type { D1Result } from './D1Types';\n\n/**\n * The single retry engine for D1 statements.\n *\n * Converged from Durable-DAV's `D1Utils.ts` (the richest, most-documented\n * variant) with ChordDHT's byte-identical copy and the straight-line port in\n * Mail-Meow. The seven consumer repos each spelled this differently\n * (`executeD1WithRetry`, `runWithRetry`, `firstWithRetry` with its own schedule);\n * the kit ships one engine plus the schedule constants, and `BaseDAO` is the\n * only intended caller.\n */\n\nconst DEFAULT_MAX_RETRIES = 3;\nconst DEFAULT_BASE_DELAY_MS = 100;\n\n/**\n * The retry schedule, exported so `BaseDAO` and any other caller cannot\n * hard-code a second, divergent one — re-deriving `baseDelayMs * 2 ** n` at a\n * call site is the same drift one level up.\n */\nconst D1_RETRY_DEFAULTS = { maxRetries: DEFAULT_MAX_RETRIES, baseDelayMs: DEFAULT_BASE_DELAY_MS } as const;\n\ninterface D1RetryOptions {\n maxRetries?: number;\n baseDelayMs?: number;\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve: (value: void) => void): unknown => setTimeout(resolve, ms));\n}\n\n/**\n * Backoff before the next attempt. Exponential, and uncapped by design: the\n * default base (100 ms) tops out under a second by attempt 3, while an operator\n * who sets a larger base gets the longer wait they asked for. The point is to\n * ride out a busy/locked D1, not to implement a rate limiter.\n */\nfunction backoffMs(baseDelayMs: number, attempt: number): number {\n return baseDelayMs * 2 ** attempt;\n}\n\nfunction toDatabaseError(errorMessage: string, context: string): DatabaseError {\n return new DatabaseError(`Failed to ${context}: ${errorMessage}`, isD1ErrorRetryable(errorMessage));\n}\n\n/**\n * Run a D1 operation, retrying transient failures with exponential backoff.\n *\n * Two failure shapes are handled, because D1 reports both:\n *\n * 1. **A result with `success: false`.** The operation resolved; the database\n * said no. Retried when the error classifies as transient.\n * 2. **A thrown error.** A transport-level rejection, which never carries a\n * `D1Result` at all. Classified from the message the same way.\n *\n * A `DatabaseError` we raised ourselves in (1) arrives back through the `catch`\n * on the retry attempt, so it must be recognised and re-thrown rather than\n * re-wrapped into a second layer of `Failed to …`.\n */\nasync function executeWithRetry<T extends D1Result>(operation: () => Promise<T>, context: string, options?: D1RetryOptions): Promise<T> {\n const maxRetries: number = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const baseDelayMs: number = options?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n const isLastAttempt = attempt === maxRetries;\n try {\n const result: T = await operation();\n if (result.success) return result;\n const errorMessage: string = result.error ?? 'Unknown database error';\n const failure = toDatabaseError(errorMessage, context);\n if (!isLastAttempt && failure.retryable) {\n await sleep(backoffMs(baseDelayMs, attempt));\n continue;\n }\n throw failure;\n } catch (error: unknown) {\n // Already classified above, or raised by the operation itself. Either way\n // re-wrapping would bury the original context.\n if (error instanceof DatabaseError) {\n if (!isLastAttempt && error.retryable) {\n await sleep(backoffMs(baseDelayMs, attempt));\n continue;\n }\n throw error;\n }\n if (error instanceof Error) {\n const failure = toDatabaseError(error.message, context);\n if (!isLastAttempt && failure.retryable) {\n await sleep(backoffMs(baseDelayMs, attempt));\n continue;\n }\n throw failure;\n }\n throw error;\n }\n }\n\n // Unreachable: the loop either returns a result or throws on its final\n // iteration. Present only so the function is total for a reader who has not\n // traced the `continue` paths.\n throw new DatabaseError(`Failed to ${context} after ${maxRetries + 1} attempts`);\n}\n\nexport { backoffMs, D1_RETRY_DEFAULTS, executeWithRetry, sleep };\nexport type { D1RetryOptions };\n"]}
|
package/dist/aes-gcm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,QAAA,MAAM,SAAS,KAAK,CAAC;AACrB,QAAA,MAAM,QAAQ,KAAK,CAAC;AAEpB,cAAM,cAAe,SAAQ,KAAK;gBACpB,OAAO,EAAE,MAAM;CAI5B;AAsBD,UAAU,iBAAiB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,iBAAe,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CASjH;AAED;;;;;;GAMG;AACH,iBAAe,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,QAAA,MAAM,SAAS,KAAK,CAAC;AACrB,QAAA,MAAM,QAAQ,KAAK,CAAC;AAEpB,cAAM,cAAe,SAAQ,KAAK;gBACpB,OAAO,EAAE,MAAM;CAI5B;AAsBD,UAAU,iBAAiB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;GAKG;AACH,iBAAe,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,CASjH;AAED;;;;;;GAMG;AACH,iBAAe,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBhH;AAED,2DAA2D;AAC3D,iBAAe,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGrF;AAED,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAC9F,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/aes-gcm.js
CHANGED
|
@@ -66,7 +66,20 @@ async function decryptSecret(envelope, encodedKey) {
|
|
|
66
66
|
const key = await importKey(encodedKey);
|
|
67
67
|
const iv = base64ToBytes(envelope.iv);
|
|
68
68
|
const ciphertext = base64ToBytes(envelope.ciphertext);
|
|
69
|
-
|
|
69
|
+
let opened;
|
|
70
|
+
try {
|
|
71
|
+
opened = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv }, key, ciphertext);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// A wrong key and a tampered ciphertext are the same failure to GCM — it
|
|
75
|
+
// authenticates the tag and refuses — and both must land as a typed error.
|
|
76
|
+
// Without this the platform's `OperationError: The operation failed for
|
|
77
|
+
// an operation-specific reason` escapes: a caller catching the documented
|
|
78
|
+
// `AesGcmKeyError` misses it, a fail-closed caller that catches by type
|
|
79
|
+
// falls through, and the one place it surfaces is a run's error message
|
|
80
|
+
// with nothing an owner can act on.
|
|
81
|
+
throw new AesGcmKeyError('The envelope could not be decrypted: wrong key or tampered ciphertext');
|
|
82
|
+
}
|
|
70
83
|
return new TextDecoder().decode(opened);
|
|
71
84
|
}
|
|
72
85
|
/** Round-trip helper for tests and one-shot migrations. */
|
package/dist/aes-gcm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../src/aes-gcm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAk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tF,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,aAAa,CAAC,QAA2B,EAAE,UAAqC;IAC7F,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC;IACxC,MAAM,EAAE,GAAe,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,UAAU,GAAe,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAClE,IAAI,MAAmB,CAAC;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,EAAkB,EAAE,EAAE,GAAG,EAAE,UAA0B,CAAC,CAAC;IACrH,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,wEAAwE;QACxE,0EAA0E;QAC1E,wEAAwE;QACxE,wEAAwE;QACxE,oCAAoC;QACpC,MAAM,IAAI,cAAc,CAAC,uEAAuE,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,2DAA2D;AAC3D,KAAK,UAAU,eAAe,CAAC,SAAiB,EAAE,UAAkB;IAClE,MAAM,QAAQ,GAAsB,MAAM,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC/E,OAAO,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { base64ToBytes, bytesToBase64 } from '@rexezuge/shared';\n\n/**\n * AES-GCM envelope for values that must be recoverable.\n *\n * Converged from the seven drifted copies of `backend-data/crypto/aes-gcm.ts`\n * (AWS, CalDAV, Durable-DAV, Edge-Git, Edge-Sonic, Mail-Meow, Mail-Otter).\n * Durable-DAV's is the canonical shape; names are de-scoped from\n * \"replication\" because every repo that encrypts a secret — replication remote\n * passwords, SES credentials, OAuth client secrets — has the same problem.\n *\n * Key material is base64 of exactly 32 bytes. A missing or wrong-sized key\n * throws rather than returning plaintext: the alternative — a helper that\n * quietly passes the value through when it cannot encrypt — would store the\n * secret in the clear on exactly the deployments that forgot to configure a\n * key, and nothing would report it.\n */\n\nconst KEY_BYTES = 32;\nconst IV_BYTES = 12;\n\nclass AesGcmKeyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'AesGcmKeyError';\n }\n}\n\nasync function importKey(encodedKey: string | undefined | null): Promise<CryptoKey> {\n if (typeof encodedKey !== 'string' || encodedKey.trim() === '') {\n throw new AesGcmKeyError('Encryption key is not configured; the secret cannot be stored');\n }\n let raw: Uint8Array;\n try {\n raw = base64ToBytes(encodedKey.trim());\n } catch {\n throw new AesGcmKeyError('Encryption key is not valid base64');\n }\n if (raw.byteLength !== KEY_BYTES) {\n throw new AesGcmKeyError(`Encryption key must decode to ${KEY_BYTES} bytes, got ${raw.byteLength}`);\n }\n try {\n return await crypto.subtle.importKey('raw', raw as BufferSource, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']);\n } catch {\n throw new AesGcmKeyError('Encryption key could not be imported as an AES-GCM key');\n }\n}\n\ninterface EncryptedEnvelope {\n ciphertext: string;\n iv: string;\n}\n\n/**\n * Encrypt one secret. The IV is random per call and returned alongside the\n * ciphertext so the caller can store the pair — reusing an IV under one key\n * destroys GCM's security guarantees outright, which is why it is not\n * internal to the ciphertext.\n */\nasync function encryptSecret(plaintext: string, encodedKey: string | undefined | null): Promise<EncryptedEnvelope> {\n const key = await importKey(encodedKey);\n const iv: Uint8Array = crypto.getRandomValues(new Uint8Array(IV_BYTES));\n const sealed: ArrayBuffer = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv: iv as BufferSource },\n key,\n new TextEncoder().encode(plaintext),\n );\n return { ciphertext: bytesToBase64(new Uint8Array(sealed)), iv: bytesToBase64(iv) };\n}\n\n/**\n * Decrypt one envelope.\n *\n * Throws on a wrong key or tampered ciphertext rather than returning garbage:\n * a fail-closed decrypt turns a config mistake into a loud, immediate error\n * instead of corrupt data flowing into a downstream request.\n */\nasync function decryptSecret(envelope: EncryptedEnvelope, encodedKey: string | undefined | null): Promise<string> {\n const key = await importKey(encodedKey);\n const iv: Uint8Array = base64ToBytes(envelope.iv);\n const ciphertext: Uint8Array = base64ToBytes(envelope.ciphertext);\n let opened: ArrayBuffer;\n try {\n opened = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv as BufferSource }, key, ciphertext as BufferSource);\n } catch {\n // A wrong key and a tampered ciphertext are the same failure to GCM — it\n // authenticates the tag and refuses — and both must land as a typed error.\n // Without this the platform's `OperationError: The operation failed for\n // an operation-specific reason` escapes: a caller catching the documented\n // `AesGcmKeyError` misses it, a fail-closed caller that catches by type\n // falls through, and the one place it surfaces is a run's error message\n // with nothing an owner can act on.\n throw new AesGcmKeyError('The envelope could not be decrypted: wrong key or tampered ciphertext');\n }\n return new TextDecoder().decode(opened);\n}\n\n/** Round-trip helper for tests and one-shot migrations. */\nasync function roundTripSecret(plaintext: string, encodedKey: string): Promise<string> {\n const envelope: EncryptedEnvelope = await encryptSecret(plaintext, encodedKey);\n return decryptSecret(envelope, encodedKey);\n}\n\nexport { AesGcmKeyError, decryptSecret, encryptSecret, roundTripSecret, IV_BYTES, KEY_BYTES };\nexport type { EncryptedEnvelope };\n"]}
|
package/dist/splitSql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitSql.d.ts","sourceRoot":"","sources":["../src/splitSql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAsHvC;AAED;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"splitSql.d.ts","sourceRoot":"","sources":["../src/splitSql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAsHvC;AAED;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAGhD;AAED;;;;GAIG;AACH,iBAAS,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD;AAED,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/splitSql.js
CHANGED
|
@@ -151,9 +151,7 @@ function splitSql(sql) {
|
|
|
151
151
|
* message quotes.
|
|
152
152
|
*/
|
|
153
153
|
function isExecutable(statement) {
|
|
154
|
-
const withoutComments = statement
|
|
155
|
-
.replaceAll(/--[^\n]*/g, '')
|
|
156
|
-
.replaceAll(/\/\*[\s\S]*?\*\//g, '');
|
|
154
|
+
const withoutComments = statement.replaceAll(/--[^\n]*/g, '').replaceAll(/\/\*[\s\S]*?\*\//g, '');
|
|
157
155
|
return withoutComments.trim().length > 0;
|
|
158
156
|
}
|
|
159
157
|
/**
|
package/dist/splitSql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitSql.js","sourceRoot":"","sources":["../src/splitSql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,QAAQ,CAAC,GAAW;IAC3B,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,IAAI,cAAc,GAAG,KAAK,CAAC;IAC3B,IAAI,SAAS,GAAG,KAAK,CAAC;I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O,CAAC,CAAC;YACjD,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACX,CAAC;QACD,OAAO,IAAI,IAAI,CAAC;QAChB,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,SAAiB;IACrC,MAAM,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IAClG,OAAO,eAAe,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,GAAW;IACvC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["/**\n * Minimal SQL statement splitter for SQLite migration files.\n *\n * Provenance: `test/integration/helpers/migrations.ts`, byte-near-identical in\n * six consumer repos, ported here verbatim because its comment-level history is\n * the specification for the edge cases (`''` escapes, block comments, trigger\n * bodies with semicolons). The kit keeps one copy: `@rexezuge/tooling`'s\n * integration helper and `@rexezuge/identity`'s migration applier both delegate\n * to this module, so the splitter cannot drift between them.\n *\n * Handles: single/double/backtick quoted strings (incl. `''` escapes), `--`\n * line comments, block comments. Semicolons inside strings or comments do not\n * split. Statements come back trimmed, without the terminating semicolon, and\n * with their leading comments attached — use `executableStatements` to drop\n * comment-only runs before sending anything to D1.\n *\n * Trigger-aware: `CREATE TRIGGER ... BEGIN ...; ... END;` bodies contain\n * semicolons that must not split. The splitter tracks the outermost BEGIN/END\n * depth after a CREATE TRIGGER header and only splits on the terminating\n * semicolon after the final END.\n */\nfunction splitSql(sql: string): string[] {\n const statements: string[] = [];\n let current = '';\n let inString = false;\n let stringChar = '';\n let inLineComment = false;\n let inBlockComment = false;\n let inTrigger = false;\n let triggerDepth = 0;\n let word = '';\n const recentKeywords: string[] = [];\n\n const flushWord = (): void => {\n if (word.length === 0) return;\n const upper = word.toUpperCase();\n word = '';\n recentKeywords.push(upper);\n if (recentKeywords.length > 6) recentKeywords.shift();\n // `CREATE [TEMP|TEMPORARY] TRIGGER` opens a body; a table merely named\n // \"trigger\" (`CREATE TABLE trigger`) must not. The word before TRIGGER\n // disambiguates.\n if (upper === 'TRIGGER' && ['CREATE', 'TEMP', 'TEMPORARY'].includes(recentKeywords.at(-2) ?? '')) {\n inTrigger = true;\n triggerDepth = 0;\n } else if (inTrigger && upper === 'BEGIN') {\n triggerDepth += 1;\n } else if (inTrigger && upper === 'END') {\n triggerDepth -= 1;\n if (triggerDepth <= 0) {\n inTrigger = false;\n triggerDepth = 0;\n }\n }\n };\n\n let index = 0;\n while (index < sql.length) {\n const char = sql[index] as string;\n const next = sql[index + 1] ?? '';\n\n if (inLineComment) {\n current += char;\n if (char === '\\n') inLineComment = false;\n index += 1;\n continue;\n }\n if (inBlockComment) {\n current += char;\n if (char === '*' && next === '/') {\n current += next;\n index += 2;\n inBlockComment = false;\n continue;\n }\n index += 1;\n continue;\n }\n if (inString) {\n current += char;\n if (char === stringChar) {\n // SQL escapes a quote by doubling it ('it''s'); do not end the string.\n if (sql[index + 1] === stringChar) {\n current += sql[index + 1];\n index += 2;\n continue;\n }\n if (sql[index - 1] !== '\\\\') inString = false;\n }\n index += 1;\n continue;\n }\n // Buffer word characters for CREATE TRIGGER / BEGIN / END tracking.\n // Any other character ends the current word.\n if (/[\\w$]/.test(char)) {\n word += char;\n current += char;\n index += 1;\n continue;\n }\n flushWord();\n if (char === '-' && next === '-') {\n inLineComment = true;\n current += char;\n index += 1;\n continue;\n }\n if (char === '/' && next === '*') {\n inBlockComment = true;\n current += char;\n index += 1;\n continue;\n }\n if (char === \"'\" || char === '\"' || char === '`') {\n inString = true;\n stringChar = char;\n current += char;\n index += 1;\n continue;\n }\n if (char === ';') {\n // Semicolons inside a trigger body do not terminate the statement.\n if (inTrigger) {\n current += char;\n index += 1;\n continue;\n }\n const trimmed = current.trim();\n if (trimmed.length > 0) statements.push(trimmed);\n current = '';\n index += 1;\n continue;\n }\n current += char;\n index += 1;\n }\n const trimmed = current.trim();\n if (trimmed.length > 0) statements.push(trimmed);\n return statements;\n}\n\n/**\n * Whether a statement is executable SQL rather than a comment.\n *\n * Checked after the split, because the splitter has to keep comments attached to\n * the statement they sit above — dropping them there would change what an error\n * message quotes.\n */\nfunction isExecutable(statement: string): boolean {\n const withoutComments = statement.replaceAll(/--[^\\n]*/g, '').replaceAll(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n return withoutComments.trim().length > 0;\n}\n\n/**\n * The executable statements of one migration file, in order: split first, then\n * filtered. A splitter that dropped comments itself would also drop the ones a\n * migration keeps beside the statement they describe.\n */\nfunction executableStatements(sql: string): string[] {\n return splitSql(sql).filter(isExecutable);\n}\n\nexport { executableStatements, isExecutable, splitSql };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/d1",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@rexezuge/errors": "1.0.
|
|
29
|
-
"@rexezuge/shared": "1.0.
|
|
28
|
+
"@rexezuge/errors": "1.0.8",
|
|
29
|
+
"@rexezuge/shared": "1.0.8"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "26.6.4",
|