@sigil-dev/plugin-sql 0.9.17 → 0.9.18
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/package.json +9 -2
- package/src/fragment.ts +31 -2
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigil-dev/plugin-sql",
|
|
3
3
|
"description": "A contract and conformance kit for SQL adapters in Grimoire",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://sigil.cane1712.dev/docs/reference/sql",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://git.cane1712.dev/sigil/sigil.git",
|
|
9
|
+
"directory": "packages/plugin-sql"
|
|
10
|
+
},
|
|
4
11
|
"module": "src/index.ts",
|
|
5
12
|
"type": "module",
|
|
6
13
|
"private": false,
|
|
7
|
-
"version": "0.9.
|
|
14
|
+
"version": "0.9.18",
|
|
8
15
|
"keywords": [
|
|
9
16
|
"grimoire",
|
|
10
17
|
"sigil",
|
|
@@ -19,7 +26,7 @@
|
|
|
19
26
|
],
|
|
20
27
|
"peerDependencies": {
|
|
21
28
|
"typescript": "^5",
|
|
22
|
-
"@sigil-dev/grimoire": "0.9.
|
|
29
|
+
"@sigil-dev/grimoire": "0.9.18"
|
|
23
30
|
},
|
|
24
31
|
"exports": {
|
|
25
32
|
".": "./src/index.ts",
|
package/src/fragment.ts
CHANGED
|
@@ -82,7 +82,36 @@ export interface Fragment<T = any> extends Promise<T[]> {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export function isFragment(v: unknown): v is Fragment<unknown> {
|
|
85
|
-
return
|
|
85
|
+
return (
|
|
86
|
+
(typeof v === "object" || typeof v === "function") &&
|
|
87
|
+
v !== null &&
|
|
88
|
+
SQL_FRAGMENT in v
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The text and values a fragment contributes when spliced.
|
|
94
|
+
*
|
|
95
|
+
* A value may also carry them behind the marker itself, as a function:
|
|
96
|
+
* `{ [SQL_FRAGMENT]: () => ({ strings, values }) }`. That is how a table or
|
|
97
|
+
* a column object from a query builder interpolates as an identifier without
|
|
98
|
+
* reserving `strings` and `values` as property names, which would collide
|
|
99
|
+
* with the column names it exposes.
|
|
100
|
+
*/
|
|
101
|
+
export function fragmentParts(v: object): {
|
|
102
|
+
strings?: readonly string[];
|
|
103
|
+
values?: readonly unknown[];
|
|
104
|
+
} {
|
|
105
|
+
const marker = (v as Record<symbol, unknown>)[SQL_FRAGMENT];
|
|
106
|
+
if (typeof marker === "function") {
|
|
107
|
+
return (
|
|
108
|
+
marker as (this: object) => {
|
|
109
|
+
strings: readonly string[];
|
|
110
|
+
values: readonly unknown[];
|
|
111
|
+
}
|
|
112
|
+
).call(v);
|
|
113
|
+
}
|
|
114
|
+
return v as Partial<Fragment<unknown>>;
|
|
86
115
|
}
|
|
87
116
|
|
|
88
117
|
export const SQL_HELPER = Symbol.for("sigil.sql.helper");
|
|
@@ -145,7 +174,7 @@ export function splice(
|
|
|
145
174
|
for (let i = 0; i < values.length; i++) {
|
|
146
175
|
const v = values[i];
|
|
147
176
|
if (isFragment(v)) {
|
|
148
|
-
const f = v
|
|
177
|
+
const f = fragmentParts(v);
|
|
149
178
|
if (!f.strings) {
|
|
150
179
|
throw new Error(
|
|
151
180
|
"This sql fragment has no `strings`, so it cannot be spliced " +
|